【发布时间】:2014-07-11 09:36:11
【问题描述】:
编辑
经过更多的挖掘,很明显,如果我在快速应用程序切换到/从 Safari 之后尝试从视图控制器类调用 segue,我会收到一个异常,指出 segue 不存在。确实如此,在屏幕上加载的 VC 中,我检查了拼写,它是 100% 正确的。
更奇怪的是,如果我从 IBAction 调用完全相同的方法,它就可以正常工作。
这是我正在使用的代码:
-(void)goToPhotoPage{
[self performSegueWithIdentifier:@"twitterAuthComplete" sender:self];
}
如果我在应用程序恢复时调用它,我会得到一个异常,但是如果我从这个 IBAction 调用它,附加到一个 UIButton,没有做任何不同的事情,segue 会按预期工作并且没有异常。
- (IBAction)twitterToPhoto:(id)sender
{
[self goToPhotoPage];
}
Arrrrgrghrhhgrgrg!
原始问题
我正在开发一个将用户照片上传到 Facebook/Twitter 的 iPad 应用程序。
作为过程的一部分,我必须跳转到 Safari 为 twitter 执行 OAuth,然后应用程序通过特定 URL 跳转回来并获取令牌等
但是由于某种原因,当应用程序重新唤醒时,我无法触发任何 segue 或手动加载任何 VC。
我的 AppDelegae 中有一个成功块,当上传完成时会调用它,它会调用 VC 中的方法来关闭微调器并转到成功视图。
微调器按预期停止,但无论我尝试什么,我都无法让 segue 工作。
一切都已连接,segue 有一个 ID,我在控制台中没有收到任何错误或异常,只是没有任何反应。在这一点之后,我可以让代码触发的 segue 工作的唯一方法是使用用户触发器连接到 UIButton,完成后他们再次开始工作。
这是我的 AppDelegate 中带有回调的代码:
- (void)postToTwitter:(NSString*)postText image:(UIImage*)image
{
NSData *data = UIImageJPEGRepresentation(image, 0.5);
[_twitter postStatusUpdate:postText
mediaDataArray:@[data]
possiblySensitive:nil
inReplyToStatusID:nil
latitude:nil
longitude:nil
placeID:nil
displayCoordinates:nil
uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
} successBlock:^(NSDictionary *status) {
ViewController * vc = [[ViewController alloc]init];
[vc triggerSuccess];
} errorBlock:^(NSError *error) {
ViewController * vc = [[ViewController alloc]init];
[vc uploadFail:error];
}];
}
在 VC 中我尝试了以下方法:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
[self.navigationController performSegueWithIdentifier:@"approveSegue" sender:self];
}
还有:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"done"];
[self.navigationController pushViewController:controller animated:YES];
}
在绝望的时刻,我什至尝试过:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
//[self.navigationController performSegueWithIdentifier:@"approveSegue" sender:self];
[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
[self performSelector:@selector(segueToSuccessPart2) withObject:nil afterDelay:0.25];
}
- (void)segueToSuccessPart2
{
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"done"];
[self.navigationController pushViewController:controller animated:YES];
}
我显然错过了一些东西,我猜这与应用程序进入后台和 VC 从内存中“卸载”并需要重新启动有关,但我不知道从哪里开始用那个。
任何帮助将不胜感激,因为我即将把电脑扔出窗外。 .
谢谢
加雷斯
编辑 1
在进行更多故障排除后,似乎在 VC 中的此调用期间:
[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
self.navigationController 为 nil 。 . .
我猜这可能是我看到的问题的原因?
编辑 2
因此,正如 Kelin 所建议的,我正在努力确保保留导航控制器。
我在 AppDelegte 中做了以下操作:
@property (nonatomic, strong) UINavigationController *navController;
和
@synthesize navController;
但是当我尝试使用下面的代码从 VC 访问它时,它仍然是 nil 。 .
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
UINavigationController *navController = appDelegate.navController;
[self dismissViewControllerAnimated:NO completion:nil];
[navController popToRootViewControllerAnimated:NO];
编辑 3
我也将它添加到 AppDelegate 中,这意味着 Navigation Controller 不再是 nil。但仍然没有任何反应。 . .
if (!self.navController)
{
self.navController = [[UINavigationController alloc]initWithNibName:@"Main" bundle:nil];
}
【问题讨论】:
标签: ios objective-c uiviewcontroller segue