加载数据后立即显示tableView popover [英] Show tableView popover as soon as data is loaded

查看:196
本文介绍了加载数据后立即显示tableView popover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一开始就显示一个TableView的Popover,当应用程序加载时。问题是tableView没有任何内容。我正在使用该方法:

i want to show a my Popover with a TableView just from the beginning, when the app loads. Problem is that the tableView doesn't have any content then. I am using that method:

 UIBarButtonItem *barItem = [self.toolbar.items objectAtIndex:0];
[self.popoverController presentPopoverFromBarButtonItem:barItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

现在,我的想法是在tableView完成数据获取时触发一个委托方法,但不幸的是没有任何事情发生:

Now, my idea was to have a delegate method which is fired when the tableView finished fetching the data, but unfortunately nothing happens:

RootViewController.h

@protocol RootDelegate <NSObject>
@optional
 -(void)didFinishLoading;
@end

RootViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
self.clearsSelectionOnViewWillAppear = NO;
[self setTitle:@"Zielscheiben"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataSaved:) name:@"DataSaved" object:nil];

[[self delegate] didFinishLoading];
}

DetailViewController.m (符合协议)

 - (void)didFinishLoading
 {
    UIBarButtonItem *barItem = [self.toolbar.items objectAtIndex:0];
    [self.popoverController presentPopoverFromBarButtonItem:barItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

  }


推荐答案

视图方法是线程化的,所以在viewDidLoad的末尾调用会发生在不可预测的时间,显然在这之前,表被填满。我看不到任何委托方法引用事件表已填满,所以我最好的猜测是保留代码并延迟其执行:

The table view methods are threaded so your call at the end of viewDidLoad will happen at an unpredictable time, apparently here before the table is filled. I can't see any delegate method refering to the event "table is filled", so my best guess would be to keep your code and delay its execution :

[[self delegate] performSelector:@selector(didFinishLoading) withObject:nil afterDelay:1]

假设1秒将足以使表被填充。

assuming 1 second will be enough for the table to be filled.

您可以探索的另一个选项是在cellForRowAtIndexPath中的某个时间点火,当您计算表已经有足够的数据,但这在某种程度上更复杂。

Another option you could explore is to fire it sometime in cellForRowAtIndexPath when you reckon the table has got enough data, but this is somehow more complex.

这篇关于加载数据后立即显示tableView popover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆