开发者

How to reload table view with new data

开发者 https://www.devze.com 2023-01-18 07:18 出处:网络
I am calling other view controller name \"cityState\" on button click which has table in it. code for calling that view on button click(which has table):

I am calling other view controller name "cityState" on button click which has table in it. code for calling that view on button click(which has table):

[self presentModalViewController:cityState animated:YES];  

now in this view controller I am loading my table with data, its working fine for first time.

For example numberofRowsInSection is like:

-(NSInteger) tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section 
{ 
    SingleTon *s = [SingleTon sharedInstance1]; 
    NSMutableArr开发者_Go百科ay *x; 
    rn =[s getRName:x]; 
    NSLog(@"rname : %@",rn); 
    return [rn count];
    [s release];  
    [ss release];  
    [x release];
}

I have a button on this view, and on button press I am going back to the view from which I called this cityStae view

//code for button click 
[self dismissModalViewControllerAnimated:YES]; 

Now I when I am back on the first view, here I am changing the value of rn (as rn I am using in table view) and calling the table view again with same button click as I did first time, view is called and it is showing with old value of rn and I can see at this time of call NSLog in my numberofRowsInSection is not reached. So the old table with old data is displayed.

My question is how to show table with new data.?


You could use [tableView reloadData];

Reference: UITableView Class Reference by Apple

But always make sure that you set the correct delegate and datasource for your UITableView.

0

精彩评论

暂无评论...
验证码 换一张
取 消