The code below works, but not the way I want. I want the UIbutton to automatically update the new value in the UITableview instead of the old value when clicked. The code only works when I press the UI buttons and after that, when I look at the UITableview then it updates the UItableview with the new values. In my application, I use UITableview as a subclass of my main classclass.as image below

I am adding a Tableview to my Mainclass, which is a "testingViewController" this way In testingViewController.h
#import "Inputtableview.h" @interface testingViewController :UIViewController<UITableViewDelegate,UITableViewDataSource> { Inputtableview *inputview; IBOutlet UITableView *inputtbl; } @end
In testViewController.m
- (void)viewDidLoad { btn1bool=FALSE; if (inputview == nil) { inputview = [[Inputtableview alloc] init]; } [inputtbl setDataSource:inputview]; [inputtbl setDelegate:inputview]; inputview.view = inputview.tableView; }
Now in the button action method
-(IBAction)input:(id)sender { btn1bool=TRUE; }
my subclass code "inputtableview.m" is shown below
- (void)viewDidLoad { [super viewDidLoad]; listOfItems=[[NSMutableArray alloc] initWithObjects:@"Iceland",@"Greenland",@"Switzerland", @"Norway",@"New Zealand",@"Greece",@"Italy",@"Ireland",nil]; array1 = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H", nil] ; } #pragma mark - #pragma mark Table View datasource methods -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { if (btn1bool) { return [array1 count]; } else { return [listOfItems count]; } [self.tableView reloadData]; } -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } NSLog(@"Row: %i", indexPath.row); if (btn1bool) { NSString *cellValue = [array1 objectAtIndex:indexPath.row]; cell.text = cellValue; } else { NSString *cellValue = [listOfItems objectAtIndex:indexPath.row]; cell.text = cellValue; } return cell; }
Any help would be indicated.