2011-06-15 53 views
0

我得到這個錯誤,當我用我剛纔實現搜索欄打。一些字母,而有些將與錯誤崩潰標題。錯誤似乎是在這裏,但我無法弄清楚什麼是錯的:「cell.textLabel.text = info.nric;」。終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「 - [NSCFString身份證]:

有人請幫助=(

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

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

    // Set up the cell... 

    if(searching){ 
     PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row]; 
     cell.textLabel.text = info.nric; 
     cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age]; 
    } 
    else { 

     //First get the dictionary object 
     NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; 
     NSArray *array = [dictionary objectForKey:@"Patients"]; 
     PatientInfo *info = [array objectAtIndex:indexPath.row]; 
     // NSString *cellValue = [array objectAtIndex:indexPath.row]; 
     cell.textLabel.text = info.nric; 
     cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age]; 
    } 

    return cell; 
} 
+0

你是如何填補'copyListOfItems'? – 2011-06-15 02:19:39

回答

1

一個你認爲只包含數組實際上PatientInfo對象包含一個NSString。所以,當你再寫入info.nric,它要求的是NSString的其nric財產,這當然是不存在的。實際的錯誤是無論你錯誤地把一個STRI納克陣列(無論copyListOfItemslistOfItems)英寸

+0

謝謝你..我實在是添加字符串對象到copyListOfItems ... 萬元的感謝!現在我知道這個錯誤消息的含義了=) – 2011-06-15 02:53:19

0

替換下面的代碼,你就會知道究竟是什麼在你的代碼會錯:

PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row]; 
if((nil != info) && ([info isKindOfClass:[PatientInfo class])) 
{ 
    if([info respondsToSelector:@selector(nric)]) 
    { 
     cell.textLabel.text = info.nric; 
    } 
} 
+0

太感謝了......理解你在哪裏=未來) – 2011-06-15 02:54:37

相關問題