Can I have the number of rows dynamically?
I’m trying to remove a tableView section header and I don’k know how… and I’ve taught that a solution would be to change the number of sections.
Right now my numberOfSectionsInTableView looks like:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
and
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
beTribesAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
switch (section) {
case 0:
return [appDelegate.firstArray count];
case 1:
return [appDelegate.secondArray count];
default:
return 0;
}
}
setting the title section like this:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
sectionTitles = [[NSMutableArray alloc] init];
[sectionTitles addObject:@"firstSection"];
[sectionTitles addObject:@"secondSection"];
NSString *sectionText = [sectionTitles objectAtIndex:section];
return sectionText;
}
I am not sure to understand the question as the answer seems trivial: just change the implementation to return some dynamic value and you are done, right?
Where
nbSectionsis a property to which you will assign the value you want so you can change it at any time you want. So what’s the matter then?PS: Of course, call
[tableView reloadData]to recompute the content of your tableView and make the new value being taken into account obviously… maybe that’s what you were missing?