gpt4 book ai didi

iOS:Grand Central Dispatch 和 ViewController

转载 作者:行者123 更新时间:2023-11-29 04:37:55 24 4
gpt4 key购买 nike

此时我非常沮丧,但我确信这是我所缺少的。在此代码中,我的新 viewController 的 Segue 在函数的其余部分执行后显示。如何让我的 viewController 成为正在执行的代码?基本上阻止 tweetText 函数发生,直到该 View 关闭我试图为用户提供一个选项来选择一个 Twitter 帐户(如果有多个帐户)。我尝试了很多不同的方法。在苹果自己的示例代码中,他们建议为用户提供一个选项,但没有给出如何在不破坏其余代码的情况下执行此操作的信息。

这是代码:

 [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {

if(granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
// Get the list of Twitter accounts.
self.accountsArray = [accountStore accountsWithAccountType:accountType];

if([self.accountsArray count] > 1 /* Check method to see if preference is still a valid account */) {
// Display user accounts if no preference has been set
[self performSegueWithIdentifier:@"TwitterAccounts" sender:self.accountsArray];

[tweet tweetText:tweetString account:self.twitterAccount type:AchievementTweet];

} else {
[tweet tweetText:tweetString account:[self.accountsArray lastObject] type:AchievementTweet];
}
});

} else {
[tweet performSelectorOnMainThread:@selector(displayText:) withObject:[NSNumber numberWithInt:403] waitUntilDone:NO];
}
}];

最佳答案

我对你的目的有点困惑,但你有两个选择。

这里确实不需要 GCD。

我建议注册一个通知,一旦您的第一个操作完成,它将执行您的第二个操作。 (类似于苹果处理图像选择器的方式,在他们的代码中,他们通知图片何时最终被保存以执行另一个功能)。

另一种方法是使用委托(delegate),在这种方法中,您可以将代码的第二部分放在单独的函数上,然后将该 Controller 声明为您要首先执行的 View Controller 的委托(delegate),然后在完成您想要完成的任何操作之后在 View Controller 上,您将要求委托(delegate)执行第二个代码,并在必要时要求委托(delegate)关闭 View 。

关于iOS:Grand Central Dispatch 和 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10826067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com