You must register a thread or class for the identifier or connect a prototype cell

I have a standard view of the main parts table with menu . The menu works, but for some reason I get the following error when I press the + button to add another cell to my application:

The application terminated due to the unannounced exception "NSInternalInconsistencyException", reason: "could not delete the cell with the identifier Cell - either register either a class for the identifier or connect the prototype cell in the storyboard"

I was looking for a solution for days

If I add to viewDidLoad :

 [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier]; 

I am not getting an error, but the added cells are not the ones that are configured in my storyboard, and do not point to the detailed view controller.

I checked several times if the identifier field for the prototype cell was filled in and matches * cellIdentifier.

From what I know, it looks like the same character as the question here .

Any help would be appreciated, and if you have the time, explain why this is wrong, what I did or why you need to add code.

Requested code (both codes added by Xcode 5.0.1 by default):

 // Code to add the button UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; self.navigationItem.rightBarButtonItem = addButton; // Code called when button is pressed: - (void)insertNewObject:(id)sender { if (!_objects) { _objects = [[NSMutableArray alloc] init]; } [_objects insertObject:[NSDate date] atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; NSDate *object = _objects[indexPath.row]; cell.textLabel.text = [object description]; return cell; } 

Also check out the photos and project files added to the comment.

+6
source share
1 answer

Replace the following line in [MAAppDelegate application:didFinishLaunching]

 UINavigationController *masterViewController = [[UINavigationController alloc] initWithRootViewController:[MAMasterViewController new]]; 

with

 UINavigationController *masterViewController = (UINavigationController *)self.window.rootViewController; 

When the application reaches didFinishLaunching , the root view controller is already configured from the storyboard (if you look at your storyboard, the root view controller is the one with the arrow pointing to it). Note that this process depends on the initializer initWithCoder:

In didFinishLaunching you drop this view controller, replacing it with the TWTSideMenuViewController instance that you configured with the new instances without the UINavigationController and MAMasterViewController . If you think about it, there is no way for [MAMasterViewController new] to know that it should be configured from a specific storyboard element. In fact, there is an API for instantiating view controllers from a storyboard: [storyboard instantiateViewControllerWithIdentifier:] . But you do not need to do this, as it is already done for you.

So the solution is simple. Just configure TWTSideMenuViewController using your existing self.window.rootViewController root view self.window.rootViewController .

+2
source

Source: https://habr.com/ru/post/957752/


All Articles