Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i actually dont see my error:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   static NSString *CellIdentifier = @"Cell";    FriendTableViewCell *cell = (FriendTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];   if (cell == nil) {       cell = [[[FriendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];       [[NSBundle mainBundle] loadNibNamed:@"FriendTableViewCell" owner:self options:nil];       cell = friendCell;   }   cell.lblNickname.text =  @"Tester";   return cell; } 

What am i doing wrong? I checked all twice.. but dont see the error.

Thanks for your help!

like image 926
phx Avatar asked Feb 08 '10 19:02

phx


2 Answers

You're returning friendCell, and it's very likely nil.

Your code looks fine, so make sure you have your Interface Builder file set up right. In FriendTableViewCell.xib, be sure the File's Owner is your table view controller and that you correctly set the cell to be an outlet to friendCell (which I assume is a UITableViewCell).

like image 123
greenisus Avatar answered Oct 13 '22 03:10

greenisus


For me, it worked doing this:

if (cell == nil) {     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } 

UPDATE
Place the above code in the following method:

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

Just put it BEFORE editing the tableViewCell

like image 40
JomanJi Avatar answered Oct 13 '22 04:10

JomanJi