UITableView lazyload - reloadData不能正常工作

时间:2011-08-11 20:30:51

标签: cocoa-touch uitableview lazy-loading

这似乎是一个经典问题,但我找不到任何有效工作解决方案的线程。

我有一个UITableView,我想从我的服务器加载一些XML“lazyload”。

我的UITableView在.h ...

中正确声明
IBOutlet UITableView *tblView;

...

@property (nonatomic, retain) IBOutlet UITableView *tblView;

...在Interface Builder中连接并在.m:

中合成
@synthesize tblView;

现在......当viewcontroller加载时,UITableView委托(numberOfSectionsInTableView,numberOfRowsInSection)被调用一次。但是我此时没有任何数据,因此这些方法返回0。

从服务器加载数据并解析后,我打电话给...

[tblView reloadData]

......但它没有任何效果。代表们根本没有被召集。

我也试过

[[self tblView] reloadData]

它也不起作用。

我甚至尝试通过performSelectorOnMainThread发出这样的调用

...

[self performSelectorOnMainThread:@selector(fillTableWith:) withObject:arrAppointmentsFromServer waitUntilDone:NO];

...

- (void)fillTableWith:(NSMutableArray *)arrAppointmentsFromServer
{
    self.arrAppointments = arrAppointmentsFromServer;

    //Calls a refresh of the tableview
    [tblView reloadData];
}

这也不起作用。

任何提示或解决方案?

提前致谢

1 个答案:

答案 0 :(得分:0)

好的,明白了......

我的视图控制器实际上是从UITableViewController ...

继承的

因此,我不必声明IBOutlet,合成它或其他......

在重新加载数据时,我只是这样做:

[[self tableView] reloadData];

因为tableView直接引用控件本身。

现在正确调用numberOfSectionsInTableView和numberOfRowsInSection方法