嗨,我收到来自udp的2000数据,并在tableview中显示值。什么是最简单的方法来做到这一点?如何从NSDictionary显示UITableView单元格中的数据?
现在我使用两个nsthreads和一个线程通过udp接收数据并将其存储在NSMutableDictionary中。另一个线程使用这些字典值更新tableview。但它崩溃了我的应用程序。
下面是一些代码我用
予存储的接收值这样
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];
委托方法我用和我用CustomTableCells显示数据作为列副。
- (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;
}
的errror是
终止应用程序由于未捕获的异常 'NSGenericException',原因: '***收集了同时列举了突变。' 2010-07-23 02:33:07.891 Centrak [2034:207]堆栈:( 42162256, 43320108, 42161198, 43372629, 41719877, 41719345, 9948, 3276988, 3237662, 3320232, 3288478, 71153942, 71153189, 71096786, 71096114, 71296742, 41650770, 41440069, 41437352, 51148957, 51149154,) 抛出'NSException'实例后终止调用
任何人都可以帮我吗?
在此先感谢.......
没有办法来帮助您提供您提供的信息。也许如果你可以为你的表视图数据源委托方法发布一些代码,你从数据字典中提取数据并放入单元格。 – 2010-07-23 06:44:27