문제

I am building an App that needs to be able to refresh by pulling, and then re-run the ViewDidLoad. So I know i could use a UIRefreshControl, but I can only find code that is used in a UITableViewController. Has anyone got an idea on how to use a UIRefreshControl in a UIView instead of in a UITableView. Thanks in advance.

도움이 되었습니까?

해결책 3

UIRefreshControl isn't meant to be used without a table. This note in the documentation specifically warns against such use:

Note: Because the refresh control is specifically designed for use in a table view that's managed by a table view controller, using it in a different context can result in undefined behavior.

So although it may be possible to get the control to work, you really shouldn't use it without a table. Rolling your own refresh control is a better solution.

Better still, try to engineer your app such that the user doesn't need to refresh the view. The app should know when new data is available. The only excuse for making the user refresh is if doing so automatically would somehow confuse the user or otherwise make the app more difficult to use.

다른 팁

try this…

[myView setNeedsDisplay];

this would reload your view controller. you can put this in a method and call it during pull to refresh…Hope this helps you. Happy coding ;)

Very easily: Keep the control as amember or property:

UIRefreshControl *_refreshControl;

Add this to your viewDidLoad method: (simply adding the control to your tableView. make sure the tableView is not nil ofcourse).

 _refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[_tableView insertSubview:_refreshControl atIndex:0];

implement the refresh method:

- (void)refresh:(UIRefreshControl *)refreshControl {
   [self reloadData];
    //Don't forget to stop the refreshing animation after data reloads.
  [_refreshControl endRefreshing];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top