简体   繁体   中英

UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:?

Yes, I have already looked at all the other posts with this error.

Here is my code: Where am I going wrong here?

- (UITableViewCell *)TableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [_myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [_cellArray objectAtIndex: indexPath.row];
return cell;
}

Your method name is wrong. Replace TableView with tableView . To prevent this kinds of error, once you set your datasource or delegate, you should use control + Space, so Xcode can help you by completing the correct method name.

Issue is with this method name:

- (UITableViewCell *)TableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Replace it with:

- (UITableViewCell *)tableView:(UITableView *)myTableView tableView:(NSIndexPath *)indexPath

Tthe actual method name is tableView:cellForRowAtIndexPath: not TableView:cellForRowAtIndexPath:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM