- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Storyboard在 iOS 7 上编写应用程序。
我有一个导航 Controller 作为我的 Root View Controller ,我在其中嵌入了一个 View Controller 。
当应用程序加载时,viewDidLoad 被调用一次,viewWillAppear 被调用一次。这是正确的(我也会检查数据并更新 View 中的 View )。
但是,在我的 View Controller 中,我有一个按钮,允许用户使用“MFMessageComposeViewController” Controller 通过短信/文本共享信息。
所以这里的代码是
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = [NSString stringWithFormat:@"Some Text Here"];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
委托(delegate)函数是
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultSent:
NSLog(@"Message Sent");
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
//[controller dismissViewControllerAnimated:YES completion:nil]; //tried this as well but same result
}
但是,当我调用 dismissViewControllerAnimated.. 时,viewDidAppear 方法被调用了两次。您知道为什么会发生这种情况吗,因为这是检查数据两次,然后将内容添加到我的 View 中两次,而不是只添加一次?
谢谢,瓦伦
第 1 - ViewDidAppear 的堆栈跟踪是
0 Sweep 0x0010a8f1 -[GoogleMapsViewController viewDidAppear:] + 56
1 UIKit 0x2fd3673f <redacted> + 410
2 UIKit 0x2fde6657 <redacted> + 182
3 UIKit 0x2fd3673f <redacted> + 410
4 UIKit 0x2fd36bcd <redacted> + 264
5 Sweep 0x000e9909 -[RESideMenu viewDidAppear:] + 88
6 UIKit 0x2fd3673f <redacted> + 410
7 UIKit 0x2fd36bcd <redacted> + 264
8 UIKit 0x2fe3321b <redacted> + 1682
9 UIKit 0x2fe32ab7 <redacted> + 170
10 UIKit 0x2fe329e3 <redacted> + 74
11 UIKit 0x2fe328c9 <redacted> + 288
12 UIKit 0x2fe323d9 <redacted> + 944
13 UIKit 0x2fd53ab7 <redacted> + 178
14 UIKit 0x2fd539cf <redacted> + 66
15 QuartzCore 0x2f9a9413 <redacted> + 234
16 libdispatch.dylib 0x37dd90af <redacted> + 22
17 libdispatch.dylib 0x37ddb9a9 _dispatch_main_queue_callback_4CF + 268
18 CoreFoundation 0x2d5625b1 <redacted> + 8
19 CoreFoundation 0x2d560e7d <redacted> + 1308
20 CoreFoundation 0x2d4cb471 CFRunLoopRunSpecific + 524
21 CoreFoundation 0x2d4cb253 CFRunLoopRunInMode + 106
22 GraphicsServices 0x322052eb GSEventRunModal + 138
23 UIKit 0x2fd80845 UIApplicationMain + 1136
24 Sweep 0x00098299 main + 116
25 libdyld.dylib 0x37dedab7 <redacted> + 2
)
第二 - ViewDidAppear 的堆栈跟踪是
0 Sweep 0x0010a8f1 -[GoogleMapsViewController viewDidAppear:] + 56
1 UIKit 0x2fd3673f <redacted> + 410
2 UIKit 0x2fde6657 <redacted> + 182
3 UIKit 0x2fd3673f <redacted> + 410
4 CoreFoundation 0x2d4e0803 <redacted> + 50
5 CoreFoundation 0x2d4da21d <redacted> + 220
6 UIKit 0x2fd3687b <redacted> + 726
7 UIKit 0x2fd36bcd <redacted> + 264
8 UIKit 0x2fe3321b <redacted> + 1682
9 UIKit 0x2fe32ab7 <redacted> + 170
10 UIKit 0x2fe329e3 <redacted> + 74
11 UIKit 0x2fe328c9 <redacted> + 288
12 UIKit 0x2fe323d9 <redacted> + 944
13 UIKit 0x2fd53ab7 <redacted> + 178
14 UIKit 0x2fd539cf <redacted> + 66
15 QuartzCore 0x2f9a9413 <redacted> + 234
16 libdispatch.dylib 0x37dd90af <redacted> + 22
17 libdispatch.dylib 0x37ddb9a9 _dispatch_main_queue_callback_4CF + 268
18 CoreFoundation 0x2d5625b1 <redacted> + 8
19 CoreFoundation 0x2d560e7d <redacted> + 1308
20 CoreFoundation 0x2d4cb471 CFRunLoopRunSpecific + 524
21 CoreFoundation 0x2d4cb253 CFRunLoopRunInMode + 106
22 GraphicsServices 0x322052eb GSEventRunModal + 138
23 UIKit 0x2fd80845 UIApplicationMain + 1136
24 Sweep 0x00098299 main + 116
25 libdyld.dylib 0x37dedab7 <redacted> + 2
)
最佳答案
我使用的是旧版本的第三方库,这导致 viewdidappear 被调用两次。此问题已通过更新库解决。
关于ios - ViewWillAppear 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967382/
我将我的 iAd/AdMob 广告代码放在... -(void)viewWillAppear:(BOOL)animated{} 广告在所有 iOS 设备上的效果都很好,就像我现在使用的那样。当我将我的
我最近对 iOS View Controller 包含感到头疼。 一切都按预期工作,除了一种特殊情况: 如果父 View Controller 包含在父 View Controller 中,而父
我有 UIScrollView 和多个 UIVIew subview 。我想更新每个 UIView 显示在 UIScrollView 的可见部分中时显示的数据。 触发的回调是什么?我尝试了 viewW
这个问题在这里已经有了答案: Why does viewWillAppear not get called when an app comes back from the background? (7
我正在使用 NSUserDefaults使一个对象在多个 UIViewController 之间保持同步UITabbarController 中使用的 s .为此,我正在实现以下 - (void)vi
我读过许多关于人们在 正确创建 View 层次结构时遇到 viewWillAppear 问题的帖子。我的问题是我不明白那是什么意思。 如果我创建一个 RootViewController 并在该 Co
当 B ->present ->C 时,它自动调用 viewWillAppear,但是当我从 C 解除到 B 并再次 B ->present ->C 时,viewWillAppear 在我触摸屏幕后调
我正在使用 Storyboard在 iOS 7 上编写应用程序。 我有一个导航 Controller 作为我的 Root View Controller ,我在其中嵌入了一个 View Control
我有一个加载记录的表格 View ,请参阅下面的代码: - (void)viewDidLoad { self.navigationItem.title=@"Accounts"; // N
在我的应用程序中,我的 View 中输入字段中的数据不断变化,因此每次将 View 显示到屏幕上时,我都需要运行一个函数来对显示的内容进行排序。 我找到了 -(void)viewWillAppear,
我有一个嵌入在导航 Controller (NAV1) 中的 View Controller (VC1)。在它的 viewWillAppear 方法中,我调用以模态方式呈现另一个 View Contr
我正在使用“viewWillAppear”来检查 UserDefaults.standard,如果我有关于默认值的数据,我想重定向到仪表板 View 并退出登录。 当我正确登录时,应用程序正常重定向,
我的 ViewWillAppear 方法中有这段代码,它只是将一组标签向下移出屏幕: override func viewWillAppear(animated: Bool) { super.
我的应用程序的工作流程是,当我失去连接时,我将应用程序重定向到特定的 viewController,然后在 viewWillAppear 上我做一些处理。 在 foreground 模式下,这非常有效
我已经设置了一个基本的测试应用程序,它显示一个包含标签的 View ,没有使用 IB。我想使用自定义 UIView 子类和自定义 UIViewController 子类。 这将按预期运行,但 MyVi
我有以下设置 只有横向 View 的 XIB 文件。此 View 连接到我的 Controller 此 View 上有一个标签连接到 IBOutlet UILabel* label 这个标签是这样配置
根据我的统计,调用 viewWillAppear 的唯一两个实例是当您初始化 View Controller 时,或者当您在导航堆栈上弹出位于其顶部的 View Controller 时(即向前插入
我有这个 View Controller class ViewController: UIViewController { override func viewWillAppear(animated
我读过许多关于人们在 正确创建 View 层次结构时遇到 viewWillAppear 问题的帖子。我的问题是我不明白那是什么意思。 如果我创建一个 RootViewController 并在该 Co
我正在编写一个应用程序,如果用户在打电话时正在查看应用程序,我需要更改 View 。 我已经实现了以下方法: - (void)viewWillAppear:(BOOL)animated { [
我是一名优秀的程序员,十分优秀!