2011-07-20 76 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"];