ios - UITableView runtime crash -


- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {  static nsstring *cellidentifier = @"mycell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      nsarray *allsections =[self.tabledatasource allkeys]; nsarray *asection = [self.tabledatasource objectforkey:[allsections objectatindex:indexpath.section]]; nsmutabledictionary *item = [asection objectatindex:indexpath.row] ;  if (cell == nil) {      /* trace 1 */     nslog(@"init: section: %i - row: %i", indexpath.section, indexpath.row);     cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];     cell.selectionstyle = uitableviewcellselectionstyleblue;      uiswitch *myswitch = [[uiswitch alloc] init];       [myswitch addtarget:self action:@selector(checkbuttontapped:) forcontrolevents:uicontroleventvaluechanged];     [myswitch seton:no animated:no];     cell.accessoryview = myswitch;     cell.accessoryview.tag = [[item objectforkey:@"id"] integervalue];     cell.textlabel.text = [item objectforkey:@"name"];     [item setobject:cell forkey:@"cell"];  } else {      /* trace 2 */     nslog(@"done: section: %i - row: %i", indexpath.section, indexpath.row);     cell = [item objectforkey:@"cell"];  }  return cell;}  

hello all,

i'm struggling uitableview + accessories crashing "sometime" @ runtime. main code tableview:cellforrowatindexpath above and, far understand, based on standard pattern uitableview.

my datasource small, it's 2 sections dataset, 1 of 6 lines , 2 lines. methods number of rows in section , number of sections implemented.

user interface in ib has required connections , working fine. uitableview in ib smaller the main view (there 2 buttons below tableview). when run app, can see in view first 6 rows (first section), last 2 rows (second section) hidden. of course, if scroll down, last 2 rows appear ...

the issue when reduce uitableview outlet size in ib. if outlet displays 2 or 3 rows first section @ runtime, app crash if scroll down. crash occur @ first row of second section. change previous situation ib outlet size, nothing has been changed in code.

error message in console :

* assertion failure in -[uitableview _createpreparedcellforglobalrow:withindexpath:], /sourcecache/uikit_sim/uikit-1448.89/uitableview.m:5678 2011-07-04 02:08:46.713 iwir client[95362:207] * terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'uitableview datasource must return cell tableview:cellforrowatindexpath:'

if @ code, see there 2 nslog traces. normal behavior code "trace 1" displayed in console first display of row, , then, if scroll , down, "trace 2". case if iboutlet of uitableview "big enough", but, said, if reduce size of outlet, console display "trace 2" first display of row.

i hope these (long) explanations clear enough, , tks bunch ...

cheers, pierre

imagine table view 6 rows out of 2 rows visible. scroll down 4th row onto visible region, cell dequeued table view not nil else clause executed.

cell = [item objectforkey:@"cell"]; 

at point there not object set key cell. objectforkey: return nil , cell nil return @ end of method. reason error says 'uitableview datasource must return cell tableview:cellforrowatindexpath:' returning nil here.

you not reusing cells via mechanism provided uitableview. method should more like,

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     nsarray *allsections =[self.tabledatasource allkeys];     nsarray *asection = [self.tabledatasource objectforkey:[allsections objectatindex:indexpath.section]];     nsmutabledictionary *item = [asection objectatindex:indexpath.row] ;     uitableviewcell *cell = [item objectforkey:@"cell"];          if (cell == nil) {         nslog(@"init: section: %i - row: %i", indexpath.section, indexpath.row);         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:nil] autorelease];          [..]     }      return cell; } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -