gpt4 book ai didi

iphone - Objective-C NSInteger 格式困惑

转载 作者:行者123 更新时间:2023-11-29 11:21:04 29 4
gpt4 key购买 nike

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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com