开发者

UITableViewDataSource Done Loading Signal to UITableViewDelegate

开发者 https://www.devze.com 2023-01-13 14:05 出处:网络
I have separate files for the UITab开发者_如何学编程leViewDataSource and UITableViewDelegate

I have separate files for the UITab开发者_如何学编程leViewDataSource and UITableViewDelegate

I am implementing a 'Pull Down to Refresh' feature on a UITableView and wish to send a signal from the UITableViewDataSource to the UITableViewDelegate to stop the loading indicator from turning.

I was wondering what the best way to send a signal between the UITableViewDataSource and UITableViewDelegate is, or if there is a better way to construct this since I feel like I'm breaking some abstraction barriers.

What I have in the Data Source:

if([tableView.delegate respondsToSelector: @selector(dataSourceDidFinishLoadingNewData)]){
    [tableView.delegate dataSourceDidFinishLoadingNewData];
}

but I get 'dataSourceDidFinishLoadingNewData' not found in protocol warning since, I guess, the function is not declared as a method of UITableViewDelegate


Just a side answer; When using the:

if([object respondsToSelector:@selector(someMethod)]){
    [object someMethod];
}

paradigm, you can just use this instead:

if([object respondsToSelector:@selector(someMethod)]){
    [object performSelector:@selector(someMethod)];
}

Might be a little lengthier, but it won't give you any warnings.


Perhaps you are aware, but there are multiple open-source implementations of pull-to-refresh. You might want to look into those before making your own. Here is one (just the first one on Google): http://github.com/leah/PullToRefresh


You propably can't do this while keeping things completely abstract. An alternative to calling the delegate via the tableViews delegate property would be exchanging an keeping references. But you could even avoid the need to keep references to each other object by using notifications to signal the delegate that loading has finished.

Check NSNotificationCenter for more information.

0

精彩评论

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