简体   繁体   English

在objective-c的表视图的每个单元格中获得相同的值

[英]getting the same value in each cell of table view in objective-c

i have check by printing the value of the cell.textlable.text in each iteration of the loop each time the value of it is as i want, but as the time of output on the simulator the value is come same for each row of cell. 我已经通过每次在循环的每次迭代中打印出cell.textlable.text的值来进行检查,每次它的值都是我想要的,但是随着在模拟器上输出的时间,每行单元格的值都相同。

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; }

The problem is likely this line: 问题可能是此行:

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

That's going to loop through every item in appDelegate.books . 这将遍历appDelegate.books 每个项目 Assuming that that's an NSArray and that this code is inside your -tableView:cellForRowAtIndexPath: method, replace that line and the next with the following: 假设那是一个NSArray ,并且此代码在您的-tableView:cellForRowAtIndexPath:方法内部,则将该行和下一行替换为以下内容:

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

(This, of course, assumes that the row numbers match the index numbers in the array. If not, adjust to match.) (当然,这假定行号与数组中的索引号匹配。如果不匹配,则进行调整以匹配。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM