Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios refreshcontrol EndRefresh必须等待子类_Ios_Objective C_Pull To Refresh - Fatal编程技术网

Ios refreshcontrol EndRefresh必须等待子类

Ios refreshcontrol EndRefresh必须等待子类,ios,objective-c,pull-to-refresh,Ios,Objective C,Pull To Refresh,我已经为我的tableview实现了一个refreshcontrol,它工作得很好。但是我想实现调用另一个类来执行该类中的进程。我希望我的refreshcontrol应该等待该类的执行 我在Player类中更改了一些数据库。现在,refreshcontrol在数据库更改进行中结束刷新 -(void)pullToRefresh{ UpdOther *updO = [[UpdOther alloc] initWithProfile:@"Player"]; [updO release]

我已经为我的tableview实现了一个refreshcontrol,它工作得很好。但是我想实现调用另一个类来执行该类中的进程。我希望我的refreshcontrol应该等待该类的执行

我在Player类中更改了一些数据库。现在,refreshcontrol在数据库更改进行中结束刷新

-(void)pullToRefresh{
    UpdOther *updO = [[UpdOther alloc] initWithProfile:@"Player"];
    [updO release];
    [refreshControl endRefreshing];
}

与其让
pullToRefresh
方法等待更新,不如在更新过程中使用一个完成块,这样
pullToRefresh
可以告诉更新过程在更新完成时要做什么

例如,与其让
initWithProfile
执行更新过程,您可以使用某种方法,例如
performUpdateWithCompletion
执行更新,但要给它一个完成块:

- (void)performUpdateWithCompletion:(void (^)(void))completionBlock
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // do synchronous update here

        // when done, perform the `completionBlock`

        if (completionBlock) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completionBlock();
            });
        }
    });
}
然后,您的
pullToRefresh
可以指定更新过程完成后要执行的操作,例如:

- (void)pullToRefresh{
    UpdOther *updO = [[UpdOther alloc] initWithProfile:@"Player"];
    __weak typeof(self) weakSelf = self;
    [updO performUpdateWithCompletion:^{
        typeof(self) strongSelf = weakSelf;
        [strongSelf.refreshControl endRefreshing];
    }];
    [updO release];
}
还有其他方法(委托模式、通知模式),但我更喜欢基于块的解决方案的即时性


顺便说一下,如果
UpdOther
正在使用
nsurconnectiondatadelegate
方法,则显然需要从其他方法调用
completionBlock
(例如,
connectionidfinishload
)。因此,在这种情况下,您可以在
UpdOther
中定义块特性,如下所示:

@property (nonatomic, copy) void (^updateCompletionBlock)(void);
或者,您可以为此块定义
typedef

typedef void (^UpdateCompletionBlock)(void);
然后在您的财产声明中使用:

@property (nonatomic, copy) UpdateCompletionBlock updateCompletionBlock;
无论如何,在这种情况下,
performUpdate with Completion
将在该属性中保存块的副本:

- (void)performUpdateWithCompletion:(void (^)(void))completionBlock
{
    self.updateCompletionBlock = completionBlock;

    // now initiate time consuming asynchronous update here
}
然后,无论您如何完成下载,都可以在此处调用保存的完成块:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do whatever extra steps you want when completing the update

    // now call the completion block

    if (self.updateCompletionBlock) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.updateCompletionBlock();
        });
    }
}

与其让
pullToRefresh
方法等待更新,不如在更新过程中使用一个完成块,这样
pullToRefresh
可以告诉更新过程在更新完成时要做什么

例如,与其让
initWithProfile
执行更新过程,您可以使用某种方法,例如
performUpdateWithCompletion
执行更新,但要给它一个完成块:

- (void)performUpdateWithCompletion:(void (^)(void))completionBlock
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // do synchronous update here

        // when done, perform the `completionBlock`

        if (completionBlock) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completionBlock();
            });
        }
    });
}
然后,您的
pullToRefresh
可以指定更新过程完成后要执行的操作,例如:

- (void)pullToRefresh{
    UpdOther *updO = [[UpdOther alloc] initWithProfile:@"Player"];
    __weak typeof(self) weakSelf = self;
    [updO performUpdateWithCompletion:^{
        typeof(self) strongSelf = weakSelf;
        [strongSelf.refreshControl endRefreshing];
    }];
    [updO release];
}
还有其他方法(委托模式、通知模式),但我更喜欢基于块的解决方案的即时性


顺便说一下,如果
UpdOther
正在使用
nsurconnectiondatadelegate
方法,则显然需要从其他方法调用
completionBlock
(例如,
connectionidfinishload
)。因此,在这种情况下,您可以在
UpdOther
中定义块特性,如下所示:

@property (nonatomic, copy) void (^updateCompletionBlock)(void);
或者,您可以为此块定义
typedef

typedef void (^UpdateCompletionBlock)(void);
然后在您的财产声明中使用:

@property (nonatomic, copy) UpdateCompletionBlock updateCompletionBlock;
无论如何,在这种情况下,
performUpdate with Completion
将在该属性中保存块的副本:

- (void)performUpdateWithCompletion:(void (^)(void))completionBlock
{
    self.updateCompletionBlock = completionBlock;

    // now initiate time consuming asynchronous update here
}
然后,无论您如何完成下载,都可以在此处调用保存的完成块:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // do whatever extra steps you want when completing the update

    // now call the completion block

    if (self.updateCompletionBlock) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.updateCompletionBlock();
        });
    }
}