Apple iOS5 和 didFinishLaunchingWithOptions
我有一个 iPhone 应用程序,它使用 UITableViewController 在屏幕上显示表格。表的数据(以及应用程序使用的更多数据)在我的应用程序委托的 didFinishLaunchingWithOptions:
方法上初始化。 该应用程序在 iOS4 上完美运行。在iOS5上,表的数据不会加载。 我检查并发现 didFinishLaunchingWithOptions:
方法现在与显示视图并行调用。因此,当获取表的大小时,我转到我的应用程序委托,它仍然没有加载表数据,因此返回“0”。
iOS 5 有办法解决这个问题吗?
以下是在我看来首先调用的方法:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
PalmsterAppDelegate *appDelegate = (PalmsterAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"tableView: %i", [appDelegate.listOfItems count]);
return [appDelegate.listOfItems count];
}
调用:[appDelegate.listOfItems count]
返回零。它清楚地表明顺序是:
调用didFinishLaunchingWithOptions(我在方法开始时打印到日志)。 然后调用tableView
并打印零。然后 didFinishLaunchingWithOptions 完成(我也在方法末尾打印到日志)。
I have an iPhone App that uses UITableViewController
to show a table on the screen. The data of the table (and more data used by the App) is initialized on: didFinishLaunchingWithOptions:
method of my App Delegate.
The App works perfectly on iOS4. On iOS5, the data of the table doesn't load.
I checked and found that the didFinishLaunchingWithOptions:
method is now called in parallel with showing the view. For this reason, when getting the size of the table, I go to my App Delegate, which still didn't load the table data and therefore return "0".
Is there a way of solving this issue in iOS 5?
Here is the method that gets called first on my view:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
PalmsterAppDelegate *appDelegate = (PalmsterAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"tableView: %i", [appDelegate.listOfItems count]);
return [appDelegate.listOfItems count];
}
calling: [appDelegate.listOfItems count]
returns zero. And it clearly shows that the order things is:
didFinishLaunchingWithOptions
is called (I print to the log on the start of the method).
Then tableView
is called and prints zero. Then didFinishLaunchingWithOptions
finishes (I print to the log at the end of the method as well).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将初始化代码移至应用委托中的单独方法中,然后从表视图控制器的
-viewDidLoad
方法调用该方法。确保只初始化一次,无论调用初始化方法多少次。
Move the initialization code into a separate method in your app delegate, and then call that method from the
-viewDidLoad
method of your table view controller.Make sure you only initialize once, no matter how many times your initialization method is called.