0
我已經實現拉到刷新在我的應用程序,但它崩潰時,我嘗試滾動,而它仍然刷新。這裏是我使用的代碼: 僅供參考,我在刷新時調用webServices。拉到刷新崩潰的應用程序,如果我嘗試滾動時刷新
在viewDidLoad中:
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self action:@selector(callWebService:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
[self callWebService:refresh];
的刷新方法:
-(void)callWebService:(UIRefreshControl *)refresh
{
static BOOL refreshInProgress = NO;
MessageWebServices *messageWebService = [[MessageWebServices alloc]init];
MessageBO *tempBO = [[MessageBO alloc]init];
if(self.flag)
{
self.navigationItem.title = @"My Posts";
tempBO.projectId = [AppConstants getProjectId];
tempBO.customerId =[AppConstants getCustomerId];
}
else
{
tempBO.projectId = [AppConstants getProjectId];
}
self.messageStore = [[NSMutableArray alloc] init];
if (!refreshInProgress)
{
refreshInProgress = YES;
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.messageStore = [messageWebService getMessageList:tempBO];
dispatch_async(dispatch_get_main_queue(), ^{
[refresh beginRefreshing];
[self.tableView reloadData];
[refresh endRefreshing];
refreshInProgress = NO;
});
});
}
}
請幫助!
你的編碼是否正確檢查一次self.messageStore值是否被添加 –
謝謝,夥計。我意識到我正在初始化陣列。我刪除了該行,現在可以運行 – sam24