开发者

Call [tableView realoadData] on RootViewController from AppDelegate?

In my app I am making an HTTP request and waiting and updating my RootViewController with the data. The problem is, I need to make a call to [tableView reloadData] after my data collection has finished, as it stands right now the tableview will either be partially populated or not populated at all. I came across this thread:

Passing an NSDictionary to a ViewController from AppDelegate

Which included this solution for setting data in the view conroller from app delegate, but I am wondering how I can adapt this for my situation? All I need, I think, is a reference to the rootViewController in appDelegate so I can call reloadData when I need to

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil tableDataSource:(NSArray*)tableData {
if (self = [开发者_Python百科super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Custom initialization
    tableDataArray = [tableData retain];

}
return self;
}

Thanks for any ideas


Declare that tableView as a property such as myTableView in that class. Now reference that class and call [classObject.myTableView reloadData];

It should work.


You can give the appDelegate a property that receives a pointer to the RootViewController and which is set by the RootViewController when it is initialized.

- (id)initWithNibName:(NSString *)nibNameOrNil 
               bundle:(NSBundle *)nibBundleOrNil 
      tableDataSource:(NSArray*)tableData 
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) 
    {
        // Custom initialization
        tableDataArray = [tableData retain];
        (MyAppDelegate *)([[UIApplication sharedApplication] delegate]).rootController = self; 
    }
    return self;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜