2011-07-20 75 views
1

所有的阵列,表视图崩溃时访问Dicitonarys

当我的表视图负荷,它访问几个委托方法。当我配置的电池,我把它调用此方法(其中“LinkedList的”是dictionarys数组):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

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

    // Configure the cell... 
    VUWIManager *vuwiManager = [VUWIManager sharedVuwiManager]; 
    NSLog(@"%@", [[vuwiManager linkedList]objectAtIndex:indexPath.row]); 
    NSLog(@"TESTZOMGOFDSOJFDSJFPODJSAPFDS"); 
    cell.textLabel.text = [[vuwiManager linkedList]objectAtIndex:indexPath.row]; 
    return cell; 
} 

它崩溃在行cell.textLabel.text = [[vuwiManager linkedList]objectAtIndex:indexPath.row]; - 我知道我做错了这里,但我米不知道它是什么。 linkedList是NSDictionarys的NSMutableArray。

编辑:如果我打电话给cell.textLabel.text = [[vuwiManager linkedList]objectAtIndex:indexPath.row];它在调试器中返回: { IP = "192.168.17.1"; desc = "description"; } 。只是想我会给出一些格式化细节。

感谢

回答

1

您试图分配对象NSDictionarycell.textLabel.text,必须通过一个NSString

难道你想:

NSString *s = [NSString stringWithFormat:@"%@", 
         [[vuwiManager linkedList]objectAtIndex:indexPath.row]]; 
cell.textLabel.text = s; 

+0

现在尝试一下。 – Baub

+0

这是完美的。谢谢!我会在8分钟内接受答案。我不敢相信我忽略了这一点。 – Baub

1

将NSString *设置为NSDictionary *可能会导致在尝试访问字典中未实现的任何字符串方法时发生崩溃。如果你想让你正在记录的字符串添加对描述的调用。

cell.textLabel.text = [[[vuwiManager linkedList]objectAtIndex:indexPath.row] description]; 
0

它看起来像你将cell.textLabel.text设置为NSDictionary而不是NSString。如果linkedList是NSDictionaries的NSMutableArray,那么您需要在objectForKey上添加以下内容:@“String key”来访问字符串

cell.textLabel.text = [[[vuwiManager linkedList]objectAtIndex:indexPath.row] objectForKey:@"STRING_KEY_HERE"];