iphone - How do I display data in a UITableView cell from an NSDictionary? -
hi received 2000 of datas udp , display values in tableview .what easiest method ?
now using 2 nsthreads , 1 thread receive data via udp , stores in nsmutabledictionary.another thread update tableview using these dictionary values. crashes app.
here code used
i stored received values this
nsmutabledictionary *dictitem customitem *item = [[customitem alloc]init]; item.sno =[nsstring stringwithformat:@"%d",sno]; item.time=currenttime; [dictitem setobject:item forkey:[nsstring stringwithformat:@"%d",sno]]; [item release];
delegate method used , used customtablecells display data column vice.
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1;
}
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [dictitem count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *identifier = @"customtablecell"; customtablecell *cell = (customtablecell *)[tableview dequeuereusablecellwithidentifier:identifier]; if (cell == nil) { cell = [[[customtablecell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier] autorelease]; } nsarray *keys = [dictitem allkeys]; customitem *item = [dictitem objectforkey:[keys objectatindex:indexpath.row]]; cell.sno.text = item.sno; cell.time.text = item.time; return cell; }
the errror
terminating app due uncaught exception 'nsgenericexception', reason: '*** collection mutated while being enumerated.' 2010-07-23 02:33:07.891 centrak[2034:207] stack: ( 42162256, 43320108, 42161198, 43372629, 41719877, 41719345, 9948, 3276988, 3237662, 3320232, 3288478, 71153942, 71153189, 71096786, 71096114, 71296742, 41650770, 41440069, 41437352, 51148957, 51149154, 2925426 ) terminate called after throwing instance of 'nsexception'
can me ?
thanks in advance.......
you have use locking because when access dictionary table view, perhaps being mutated other thread. try @ nslock docs. before mutating dictionary [mylock lock];
, after mutating [mylock unlock];
. similar in other thread: before enumerating dictionary [mylock lock];
, after getting values [mylock unlock];
. mylock
nslock object , must shared between threads.
Comments
Post a Comment