Keeano Keeano - 8 months ago 38
Objective-C Question

Array to UITableView

This sounds like it's easy and from the tutorials it looks very easy.

I have followed the tutorials from their words EXACTLY and still can not get the array to display on my UITableView.

Here is my code.

- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
salesArray = [[NSMutableArray alloc] init];

//Add items
[salesArray addObject:@"Credit"];
[salesArray addObject:@"Debit"];
[salesArray addObject:@"EBT"];

//Set the title
self.navigationItem.title = @"Sale Type's";

-(NSInteger)tableView:(UITableView *)tableView
{return [salesArray count];}

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero
NSString *value = [salesArray objectAtIndex:indexPath.row];
cell.textLabel.text = value;
return cell;

And yes, I have declared it in the .h file and the .m file.

Any help in any directions would be great, thank you!


Declare your salesArray as your property and in the the cellForRowAtIndexPath, use

cell.textLabel.text = [self.salesArray objectAtIndex:indexPath.row];