2010-05-19 57 views
0

我通過在循環的每次迭代中打印cell.textlable.text的值來檢查每次它的值如我所願,但作爲在模擬器上輸出的時間的值對於每行單元來說都是相同的。獲取相同的值在每個單元格中的表視圖在objective-c

my code: 
     for(i=0;i<[appDelegate.books count];i++) 
    { 

     Book *aBook= [appDelegate.books  
    objectAtIndex:i]; 

     NSString *string1 =aBook.Latitude; 
     NSString *trimmedString = [string1  
      stringByTrimmingCharactersInSet:[NSCharacterSet  
      whitespaceAndNewlineCharacterSet]]; 
    double myDouble = [trimmedString doubleValue]; 

    NSString *string2=aBook.Longitude; 

    NSString *trimmedString1 = [string2 
      stringByTrimmingCharactersInSet:[NSCharacterSet 
     whitespaceAndNewlineCharacterSet]]; 

    double mDouble = [trimmedString1 doubleValue]; 

    if((((myDouble<(a+5.021777))&&(myDouble>(a- 

      8)))||((mDouble<=(b+10))&&(mDouble>=(b-10))))) 
    { 

    NSString *a1=aBook.AreaName; 
     NSString *b1=[a1 stringByAppendingString:@","]; 
     NSString *s=aBook.STREET_NAME; 
     NSString *c=[b1 stringByAppendingString:s]; 
    cell.textLabel.text = c ; 

    }  
    } 
    return cell; } 

回答

0

這個問題可能這一行:

for(i=0;i<[appDelegate.books count];i++) 

這是在appDelegate.books要遍歷每個項目。假設這是一個NSArray並且該代碼是您的-tableView:cellForRowAtIndexPath:方法內,更換該行和下一使用以下:

Book *aBook = [appDelegate.books objectAtIndex:indexPath.row]; 

(這當然,假設行數陣列中相匹配的索引號如果沒有,調整爲匹配。)

相關問題