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
numberOfRowsInSection:(NSInteger)section
{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
reuseIdentifier:CellIdentifier]autorelease];
}
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];
I am assuming that your view controller extends UITableViewController? If so, you just need to add this line at the end of your viewDidLoad and/or viewDidAppear methods:
[self.tableView reloadData];
Also, I would use self.salesArray instead of salesArray. Not exactly sure what the difference is, but I have had issues in the past not prepending "self" to some of my variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With