ios - i want to create CustomCell But it give some error, How to Solve it?? error is describe below -


- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"customcell"; customcell *cell = (customcell *) [tableview dequeuereusablecellwithidentifier:cellidentifier];  if (cell == nil) {     if ([[uidevice currentdevice] userinterfaceidiom] == uiuserinterfaceidiomphone) {         cell.accessorytype = uitableviewcellaccessorydisclosureindicator;     } } cell.celldate.text=@"date"; cell.celldescription.text =@"description"; cell.cellimageview.image = [uiimage imagenamed:@"sample.png"]; cell.celltitle.text = @"title"; nslog([cell description]); return cell; 

}

 nslog([cell description]); 

return null

above method gives below error: here

terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'uitableview datasource must return cell tableview:cellforrowatindexpath:'

you not allocating new cell inside if (cell == nil) bit. need allocate new uitableviewcell return.

the way de-queueing works is:

  1. ask table view re-useable cell cellidentifier

  2. if cell nil allocate new cell using cellidentifier can re-used in future.

so go like:

static nsstring *cellidentifier = @"customcell"; //ask cell cell identifier customcell *cell = (customcell *) [tableview dequeuereusablecellwithidentifier:cellidentifier];  //if cell nil if (cell == nil)  { //allocate new cell identifier     cell = [[customcell alloc] init];//put actual init method here } if ([[uidevice currentdevice] userinterfaceidiom] == uiuserinterfaceidiomphone)  {     cell.accessorytype = uitableviewcellaccessorydisclosureindicator; } cell.celldate.text=@"date"; cell.celldescription.text =@"description"; cell.cellimageview.image = [uiimage imagenamed:@"sample.png"]; cell.celltitle.text = @"title"; nslog([cell description]); return cell; 

hope helps


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -