Ios 如果我在刷新时尝试滚动,则拉动刷新应用程序会崩溃

Ios 如果我在刷新时尝试滚动,则拉动刷新应用程序会崩溃,ios,objective-c,pull-to-refresh,Ios,Objective C,Pull To Refresh,我已经在我的应用程序上实现了拉刷新,但当我试图在应用程序仍在刷新时滚动时,它崩溃了。以下是我正在使用的代码: 仅供参考,我正在刷新时调用webServices 在ViewDidLoad中: UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];

我已经在我的应用程序上实现了拉刷新,但当我试图在应用程序仍在刷新时滚动时,它崩溃了。以下是我正在使用的代码: 仅供参考,我正在刷新时调用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;
            });
        });
    }

}

请帮忙

我从未使用过
beginRefreshing
方法。您可以轻松地将刷新控件添加到tableView中

#pragma mark Refresh Method

-(void)startRefreshing {
    if (!self.refreshControl) {
        // Initialize the refresh control.
        self.refreshControl = [[UIRefreshControl alloc] init];
        self.refreshControl.backgroundColor = CRREFRESHBGCOLOR;
        self.refreshControl.tintColor = [UIColor whiteColor];
        [self.refreshControl addTarget:self action:@selector(callWebservice) forControlEvents:UIControlEventValueChanged];
        [yourTable addSubview:self.refreshControl];//add refresh control to your table
    }
}

-(void)endRefreshing {
    if (self.refreshControl) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"MMM d, h:mm a"];
        NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
        NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                                    forKey:NSForegroundColorAttributeName];
        NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
        self.refreshControl.attributedTitle = attributedTitle;

        [self.refreshControl endRefreshing];
    }
}

调用/完成web服务方法调用后
[自结束刷新]
方法并重新加载您的表
[yourTable reloadData]

添加self.messageStore值或不添加self.messageStore值后,即可对您的编码进行检查谢谢,伙计。我意识到我再次初始化了数组。我去掉了那条线,它现在可以工作了