0

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?

1

1 Answer 1

1

Make the array an instance variable. Then you can access it from any instance method.

Sign up to request clarification or add additional context in comments.

2 Comments

And what would the second part be? Would [NSString stringWithFormat:"%@", [objectAtIndex:1]; be correct to access each object?
Sorry, forgot to answer the second part: Use the %@ format with [array objectAtIndex:idx].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.