UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

后端 未结 15 798
梦如初夏
梦如初夏 2020-11-28 03:03

I\'ve setup a UIRefreshControl in my UITableViewController (which is inside a UINavigationController) and it works as expected (i.e. pull down fires the correct event). Howe

15条回答
  •  眼角桃花
    2020-11-28 03:55

    I use the same technique for show user "data is update" visual sign. A result user bring app from background and feeds/lists will be update with UI like users pull tables to refresh himself. My version contain 3 things

    1) Who send "wake up"

    - (void)applicationDidBecomeActive:(UIApplication *)application {
        [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationHaveToResetAllPages object:nil];
    }
    

    2) Observer in UIViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceUpdateData) name:kNotificationHaveToWakeUp:nil];
    }
    

    3)The protocol

    #pragma mark - ForcedDataUpdateProtocol
    
    - (void)forceUpdateData {
        self.tableView.contentOffset = CGPointZero;
    
        if (self.refreshControl) {
            [self.refreshControl beginRefreshing];
            [self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];
            [self.refreshControl performSelector:@selector(endRefreshing) withObject:nil afterDelay:1];
        }
    }
    

提交回复
热议问题