开发者

How to refresh UITableViewController in iphone/iPad

开发者 https://www.devze.com 2023-04-11 03:37 出处:网络
-(void)reloadView{ NSLog(@\"IN RELOAD VIEW \"); [[self tableView] reloadData]; } - (void)viewDidLoad { UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
 -(void)reloadView{
    NSLog(@"IN RELOAD VIEW ");
    [[self tableView] reloadData];
  }


  - (void)viewDidLoad {
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    [self navigationItem].rightBarButtonItem = barButton;

    [activityIndicator startAnimating];

    [self callStudentsWebService];
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
    [self setTit开发者_如何学Cle:@"Students"];

    self.navigationController.toolbarHidden = NO;
    self.navigationController.toolbar.barStyle = UIBarStyleBlack;
     UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithTitle:@"Add Student"        style:UIBarButtonItemStyleBordered target:self action:@selector(addStudent)];
    UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *import =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:self action:@selector(addStudent)];
    NSArray* toolbarItems = [NSArray arrayWithObjects:add,flexible,import, nil];
    self.toolbarItems = toolbarItems;
  }

Above is my Code in a Class which is a subclass of UITableViewController. Now my problem is when I come onto the screen First Time it get the records from web service from the method [self callStudentsWebService] . Now i have a button in uitoolbar in the same view which updates the list . I am calling the reloadView method to refresh the List but it calls the numberOfRowsInSection and viewDidLoad method but does not call cellForRowAtIndexPath method. But when i goto other screen and come back again it does refresh my List from start.

What could be the reason ?? Please help i am new in iPad Development. And i m doing all this in iPad.

Thanks alot

EDITED

@interface StudentsList : UITableViewController {
DetailViewController *detailViewController;
UIToolbar *toolbar;
UIActivityIndicatorView *activityIndicator;
}


May be your data.count is 0? If there is some data it should call cellForRowAtIndexPath after [[self tableView] reloadData];


Do the refresh code in another separate method -(void)refreshData then call this whenever you want such as in -viewDidLoad or on a button tap...


Try to call -(void)reloadView from

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    [self reloadView];
}
0

精彩评论

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