2014-04-04 30 views
0

我有一個表,當我選擇我行執行此命令:獲取陣列的關鍵與indexPath.row

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 


    InfoClienteViewController *infoViewController = [[InfoClienteViewController alloc] init]; 
    [self.navigationController pushViewController:infoViewController animated:YES]; 

    [infoViewController setIdt:idt[indexPath.row]]; 


    NSLog(@"You Select -> %zd",idt[indexPath.row]); 

} 

在我的數組(IDT)我有這樣的價值觀:

  1. [0] - > 2
  2. [1] - > 3
  3. [2] - > 4

所以,當我點擊我桌子上的第一行(現在indexPath.row是[0]),NSLog顯示數字2,但返回數字4451524096,爲什麼?我該如何解決它?

回答

5

數組不能包含普通數字(原始數據類型,如int,float,NSInteger,...),它們只能保存對象。所以,當你登錄idt[indexPath.row]作爲一個普通的數字,你會得到亂碼。

你的日誌應該是:

NSLog(@"You Select -> %@", idt[indexPath.row]); 

正常登錄的對象。

0

如果你的數組包含int或整數值,那麼你需要像下面這樣訪問。但要確保你的數組包含所有的int值。

//對於int數據類型訪問它這樣

NSLog(@"You Select -> %d", idt[indexPath.row].intValue); 

//對於整數數據類型的訪問它像這樣

NSLog(@"You Select -> %ld", idt[indexPath.row].integerValue);