访问数组中的对象?
我有一个数组设置如下:
NSMutableArray *array = [[NSArray alloc] initWithObjects: @"Item 1", @"Item 2", @"Item 3", @"Item 4", @"Item 5", nil];
我想访问数组的内容以在 NSString 中显示它们,但我不确定要使用什么,例如:
[NSString stringWithFormat:@"%c", [objectAtIndex:0]];
[NSString stringWithFormat:@"%c", [objectAtIndex:1]];
但我的数组是在 - (void)viewDidLoad 中声明的
并且我需要在 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中访问它们 - 我如何访问它们并在中显示它们一个 NSString?
I have an array set up like:
NSMutableArray *array = [[NSArray alloc] initWithObjects: @"Item 1", @"Item 2", @"Item 3", @"Item 4", @"Item 5", nil];
And I would like to access the contents of the array to display them in an NSString but I am unsure what to use, for example:
[NSString stringWithFormat:@"%c", [objectAtIndex:0]];
[NSString stringWithFormat:@"%c", [objectAtIndex:1]];
But my array is declared in - (void)viewDidLoad
and I need to access them in - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- How would I access them and display them in an NSString?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使数组成为实例变量。然后您可以从任何实例方法访问它。
Make the array an instance variable. Then you can access it from any instance method.