开发者

Table View Crashing When Accessing Array of Dicitonarys

All,

When my table view loads, it accesses several delegate methods. When I configure the cell, I have it calling this method (where "linkedList" is an array of 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;
}

It crashes at the line cell.textLabel.text = [[vuwiManager linkedList]objectAtIndex:indexPath.row]; - I know I'm doing something wrong here but I'm not sure what it is. Again, linkedList is a NSMutableArray of NSDictionarys.

Edit: if I call cell.textLabel.text = [[vuwiManager linkedList]objectAtIndex:indexPath.row]; it returns: { IP = "192.168.17.1"; desc = "description"; } in the debugger. Just thought I'd give a little bit of formatting details.

Thanks


You are trying to assign an object NSDictionary to cell.textLabel.text, which must be passed a NSString.

Did you want :

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

?


Setting an NSString * to an NSDictionary * will likely result in a crash when it tries to access any string methods that are not implemented in the dictionary. If you want that string you are logging add a call to description.

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


It looks like you are setting cell.textLabel.text to a NSDictionary instead of an NSString. If linkedList is an NSMutableArray of NSDictionaries, then you need to add on objectForKey:@"String key" to access the string

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜