Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView dataSource must return a cell from tableView: cellForRowAtIndexPath
    primarykey
    data
    text
    <p>I have set up a <code>UIViewController</code> with a table view and cell added. The delegate and data source are linked to the table view. However I getting this error and I am confused as to why. The code works when I use it with a <code>UITableViewController</code> but not with a <code>UIViewcontroller</code>. The reason for wanting to use a <code>UIViewController</code> is that the navigation bar scrolls with the table when using a <code>UITableViewController</code> and I was advised on here to use a <code>UIViewController</code> and add the Table view.</p> <pre><code>#import "ObViewControllerObservationsTable.h" #import "ObAppDelegate.h" #import "Observations.h" #import "ObViewControllerTableDetail.h" #import "ObViewControllerMainMenu.h" @interface ObViewControllerObservationsTable () @property (nonatomic, strong) NSArray *teacherNames; @property (nonatomic, readonly) NSManagedObjectContext *managedObjectContext; @property (weak, nonatomic) IBOutlet UIBarButtonItem *detailsButton; @end @implementation ObViewControllerObservationsTable - (void)viewDidLoad { [super viewDidLoad]; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Observations"]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"obsTeacherName" ascending:YES]]; NSError *error = nil; self.teacherNames = [self.managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; [self.tableView reloadData]; } - (NSManagedObjectContext *) managedObjectContext { return [(ObAppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.teacherNames.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"teacherCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; Observations *currentList = [self.teacherNames objectAtIndex:indexPath.row]; cell.textLabel.text = currentList.obsID; return cell; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.managedObjectContext deleteObject:[self.teacherNames objectAtIndex:indexPath.row]]; [self.managedObjectContext save:nil]; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Observations"]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"obsTeacherName" ascending:YES]]; NSError *error = nil; self.teacherNames = [self.managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; if (self.teacherNames.count == 0) { self.detailsButton.enabled = NO; } else { self.detailsButton.enabled = YES; } [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { } } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { obsID = [[self.teacherNames objectAtIndex:indexPath.row] obsID]; self.detailsButton.enabled = YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload