【发布时间】:2015-12-02 14:26:03
【问题描述】:
我已经在我的应用程序上实现了“拉动刷新”,但是当我尝试滚动而它仍在刷新时它会崩溃。这是我正在使用的代码: 仅供参考,我在刷新时正在调用 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 值
-
谢谢,伙计。我意识到我正在再次初始化数组。我删除了那条线,它现在可以工作了
标签: ios objective-c pull-to-refresh