[英]how to add the content of the cell of table view in other view when clicked on cell in objective-c
[英]getting the same value in each cell of table view in objective-c
我已經通過每次在循環的每次迭代中打印出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; }
問題可能是此行:
for(i=0;i<[appDelegate.books count];i++)
這將遍歷appDelegate.books
每個項目 。 假設那是一個NSArray
,並且此代碼在您的-tableView:cellForRowAtIndexPath:
方法內部,則將該行和下一行替換為以下內容:
Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
(當然,這假定行號與數組中的索引號匹配。如果不匹配,則進行調整以匹配。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.