- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑
经过更多的挖掘之后,很明显,如果我在快速应用程序切换到/从 Safari 后尝试从 View Controller 类调用 segue,我会得到一个异常,说明 segue 不存在。确实如此,在屏幕上加载的 VC 中,我检查了拼写,它 100% 正确。
更奇怪的是,如果我从 IBAction 调用完全相同的方法,它工作正常。
这是我使用的代码:
-(void)goToPhotoPage{
[self performSegueWithIdentifier:@"twitterAuthComplete" sender:self];
}
如果我在应用程序恢复时调用它,我会得到一个异常,但是如果我从这个 IBAction 调用它,附加到一个 UIButton,没有做任何不同的事情,segue 将按预期工作,没有异常。
- (IBAction)twitterToPhoto:(id)sender
{
[self goToPhotoPage];
}
啊啊啊啊啊啊啊啊啊!
原始问题
我正在开发一个将用户照片上传到 Facebook/Twitter 的 iPad 应用程序。
作为该过程的一部分,我必须跳转到 Safari 为 Twitter 执行 OAuth,然后该应用程序通过特定 URL 跳回并获取 token 等
但是由于某些原因,当应用程序重新唤醒时,我无法触发任何 segue 或手动加载任何 VC。
我的 AppDelegae 中有一个成功 block ,它在上传完成时被调用,它调用 VC 中的方法来关闭微调器并转到成功 View 。
微调器按预期停止,但无论我尝试什么,我都无法让 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 的建议,我正在努力确保保留导航 Controller 。
我在 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];
}
最佳答案
问题是您尝试使用以编程方式创建的 View Controller 从 Storyboard执行转场。
你使用 -performSegueWithIdentifier: sender:
完全错误。在此方法中,“sender”是一个按钮,或任何其他控件,其操作初始化 segue,但不是要推送的 View Controller 。
通常 segue 是用 Storyboard创建的。但是,如果您确实需要手动创建它,请调用:
-[UIStoryboardSegue initWithIdentifier:source:destination:]
源和目标是 View Controller 。
阅读:https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-storyboard/StoryboardSegue.html或者这个(关于自定义 segues):
关于ios - 无法触发 Segue 手动加载 VC - self.navigationController 为 Nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694621/
在检查对象是否为 nil 时,有人使用 1: if (object == nil) { //... } 有人用 2: if (nil == object) { //... } 1和2有
func InsertApData(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body)
为什么 nil.to_s 返回 "",而 nil.inspect 返回 "nil"(当显然 .inspect 使用 .to_s 方法) 最佳答案 "inspect" method of the Obj
运行时间 https://play.golang.org/p/sl12vfS9vP package main import "fmt" func main() { err := run()
我可以将三元条件运算符用于 if {} else {} 语句,如下所示:a ? x : y,还是问题?回答 1 : 回答 2。 是否可以使用这种格式来检查,而不是 a 是 true 还是 false,
无法弄清楚这里出了什么问题。按照设计设置说明,用谷歌搜索我能想到的一切,仍然没有运气。 undefined method `email' for # Extracted source (around
今天写一些 rspec 时,我遇到了一些意外的行为,将日期(和时间)实例与 nil 进行比较。这是一个使用原始 ruby 的示例(没有 Rails 或其他库): user@MacBook-Work
我将数据类型的非零值分配给非可选属性,然后将其分配给可选属性,最后用所述数据实例化图像。当可选项通过 if-let 子句时,它的 block 执行,抛出错误: Fatal error: Unexpec
swift 5.1 。 考虑以下。 let x: Any? = nil let y: Any = x print("x \(x)") // x nil pri
请耐心听我解释这一点, 我正在创建一个聊天室,用户可以在其中上传照片供其他人查看。当用户点击图标时,他们可以将照片上传到我的 Firebase 数据库(这已成功完成,我已经对此进行了测试)。照片的 U
我的 xCode 5.0 目前遇到一个奇怪的问题:一个对象在控制台中似乎为 nil,但同时它可以通过代码访问。 图 1:对象似乎为零 图2:NSLog(@"%@", imgDownloader) 的输
我有一个实现协议(protocol)的类,以便添加 3 个变量。我专门设置了图像变量,调试器显示该变量存在,但是在我打印它时在代码中显示为 nil,我的 if let 语句也认为该变量为 nil。 @
这个问题在这里已经有了答案: Swift 2 ( executeFetchRequest ) : error handling (5 个答案) 关闭 7 年前。 开始在 SWIFT 中学习编码,每次
两者 (not 'nil) 和 (not nil) 求值为T,那么'nil和nil有什么区别吗?那么 ''nil 呢?如果 ''nil 的计算结果为 'nil,那么 ''nil 是否也应该计算为 ni
(if '(nil nil) 'print-true 'print-false) (if '(nil) 'print-true 'print-false) 在上面的代码
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: obj.nil? vs. obj == nil 我发现了一个问题 - == nil 和 nil 哪个更好?
此代码段抛出异常: x = nil jsoned = x.to_json puts 'x.to_json=' + jsoned.inspect puts 'back=' + JSON.parse(js
基本上我有一个对象想要传递给前端。我在后端记录了它,它不是空的,但是在前端,当我提醒它时,它变成了空。 ... presentation := &presentationStruct { Obje
我创建了一个自定义错误类型来包装错误,以便在 Golang 中更轻松地进行调试。当有错误要打印时它可以工作,但现在它会引起 panic 。 Demo type Error struct { E
写一个符合我当前问题的标题有点难..我有一个 main() 函数,它使用另一个包 (database_sql) 中的函数。该函数初始化一个全局变量 sql.DB*。初始化后,变量不为nil,但是对于其
我是一名优秀的程序员,十分优秀!