I have an app where a UITableView is populated by a NSMutableArray. The problem is that when I add strings to the Array, it isn’t at the TableView. Here’s the code:
.h
<UITableViewDelegate, UITableViewDataSource>{
IBOutlet UITableView *table;
NSMutableArray *array;
}
.m
- (void)viewDidLoad{
array=[[NSMutableArray alloc] init];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSInteger row = [indexPath indexAtPosition:1];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
-(void)addObjectsToTheArray{
NSString *stringA = @"something";
NSString *stringB = @"moreofsomething" ;
[array addObject:stringA];
if (![stringA isEqual: stringB]) {
stringA = @"somethingtoo"
[array addObject: stringB];
[table beginUpdates];
}
}
Anyone has idea why it doesn’t reload the data? I don’t know why it doesn’t work, and it doesn’t give to me any error.
Do you invoke
[table reloadData];somewhere in your code?Have you set
dataSourceanddelegatefor yourtable?