iphone - Objective-C NSInteger 格式困惑

标签 iphone objective-c ios

我知道我在这里遗漏了一些明显的东西,但我似乎无法编写我的 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];
}

问题是,如果我使用 %@ 进行打印,它可以正常工作,但实际上不应该,因为这不是正在打印的对象,而是一个整数。如果我使用整数调用,它会出错,给我一个非常离谱的整数。这听起来像是答案只是“使用 %@”,但问题是在其他情况下,当我尝试使用它作为解决方案时(例如在下一个 Controller 上),我得到一个 exc_bad_access。请告诉我我在这里遗漏了一些明显的东西......

最佳答案

根据 Apple's Documentation

%i 将起作用.

A UIView's tag is an NSInteger ,这是 %i 指定的内容。

关于iphone - Objective-C NSInteger 格式困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7123242/

相关文章:

iphone - Facebook 访问 token - 测试强制过期

iphone - iPhone 表中的 json 数据

objective-c - NSNumber 和 float - 类型类型转换怪事

ios - 获取 UICollectionViewCell 的 indexPath

objective-c - mouseDragged 事件被另一个 View 窃取

iphone - Xcode、iPhone SDK 中的错误处理

iphone - 在 Web View 中使用 YouTube 播放器的 iPhone 上为 "Movie Format Not Supported"

ios - 从 UIImageView 和 UITextView 创建 UIImage

ios - 使用 FCM 推送通知在 ios ionic 中不起作用

ios - Realm - 订购元素?