2011-08-19 35 views
1

我知道我錯過了很明顯的東西,但我似乎無法讓我的nsinteger東西寫入傳遞變量並將它們放入字符串。這是頂起來的代碼的一部分。Objective-C NSInteger格式化混淆

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *chosenCell = [tableView cellForRowAtIndexPath:indexPath]; 
    //need to get the ID number for this guy 
    NSInteger id_number = chosenCell.tag; 
    NSLog(@"This is the id number I'm sending to the item list %@", id_number); 
    NSLog(@"This is the id number I'm sending to the item list %i", id_number); 
    ItemViewController *vc = [[ItemViewController alloc] initWithPlayer:id_number andGame:gameId]; 
    [[self navigationController] pushViewController:vc animated:YES]; 
    [vc release]; 
} 

的問題是,如果我打印使用%@它正常工作,但它實在不應該,因爲這不是正在打印的對象,但一個整數。如果我使用整數調用,它的功能錯誤,給我一個真正的牆整數。這聽起來像答案只是「使用%@」,但問題是,在其他情況下,當我試圖使用它作爲解決方案(如在下一個控制器),我得到exc_bad_access。請告訴我我在這裏丟失的東西很明顯...

回答

1

%i將工作,根據Apple's Documentation

A UIView's tag is an NSInteger,這是%i指定的值。

+0

剛剛嘗試過,並再一次,我得到一個頂起來的號碼... – drapergeek

+0

然而,您的評論只是讓我意識到我在做什麼。問題不在於打印它,而在於標籤的設置位置。我只是試圖將一個字符串「投」到一個NSInteger而不是使用integerValue方法。這解決了這個問題。 – drapergeek