I’ve got a tableView in storybord and UISegmentedControl to populate the over mentioned table with with different data and different design. My problem is that numberOfRowsInSection meth doesn’t react when I switch UISegmentedControl.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(self.segment.selectedSegmentIndex==0)
{
return [self.items count];
NSLog(@"Nominals: %d",self.items.count);
}
if(self.segment.selectedSegmentIndex==1)
{
return [self.coinageArr count];
NSLog(@"Coinage: %d",self.coinageArr.count);
}
//return 0; Complains about no return.
}
Well, NSLogs do not work while navigating. And how to return NSInteger in this case?
Thanx in advance.
EDIT: For shannoga
segment controller switch method:
-(IBAction)segmentValueChaged:(id)sender
{
switch (self.segment.selectedSegmentIndex)
{
case 0:
{
DBAccess *access=[[DBAccess alloc]init];
self.items=[access returnNominals:self.entityID nk:fromPeriod];
[access closeDataBase];
self.tableView.hidden=NO;
[self.tableView reloadData];
break;
}
case 1:
{
DBAccess *access=[[DBAccess alloc]init];
self.coinageArr=[access returnCoinage:fromPeriod period:self.entityID];
self.tableView.hidden=NO;
[self.tableView reloadData];
break;
}
}
}
Change it to:
else.As @Ryan said you should use
[tableview reloadData]on your UISegmentedControl change. Then it will be better if you change theself.itemsarray in yourvalueChangedmethod and leave thenumberOfRowsInSectionwith out a change so it will look like that:Good Luck