iphone - 推送 View Controller - 未调用 viewDidAppear

标签 iphone objective-c ios uinavigationcontroller modalviewcontroller

我有这段代码来推送 View Controller :

        // Setup the animation
[self.navigationController pushViewController:self.productView animated:YES];

self.productView.imageURL = [product imageURL];

// Set the title of the view to the product's name
self.productView.title = [product name];

// Set the label text of all the labels in the view
[self.productView.caloriesL setText:[product calories]];
[self.productView.fatL setText:[product fat]];
[self.productView.saturatesL setText:[product saturates]];
[self.productView.sugarL setText:[product sugar]];
[self.productView.fibreL setText:[product fibre]];
[self.productView.saltL setText:[product salt]];

但是当 productView 出现时,委托(delegate)方法 viewDidAppear 不会被调用。我在谷歌上查找了这个问题,有很多不同的解决方案,没有一个可以应用于我的问题。我在以前的解决方案中遇到了类似的问题,但我通过在 viewDidLoad 方法中手动调用 viewDidApear 解决了这个问题。不幸的是,在这种情况下我不能这样做,因为 viewDidLoad 只被调用一次(在第一次推送时)。有谁知道如何解决这一问题?

谢谢,

jack 纳特金斯

编辑:

这是 productView(和选择器)中的 viewDidAppear 方法:
- (void)viewDidAppear:(BOOL)animated{
//Start animating the activity indicator
[indicator startAnimating];
//Perform this method in background
[self performSelectorInBackground:@selector(loadImage) withObject:nil];

}
- (void) loadImage {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Load the animals image into a NSData boject and then assign it to the UIImageView
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];
    UIImage *image = [[UIImage alloc] initWithData:imageData];
    self.imageView.image = image;

    //Stop animating the activity indicator
    [indicator stopAnimating];

    [pool drain]; //see comment below
}

最佳答案

第一:您绝对不想调用任何标准 viewWillLoad , viewDidLoad , viewWillAppear等方法手动。让操作系统为您完成。

二:你能告诉我们你的viewDidAppear方法在您的 self.productView 中实现实例? (只是预感,您不希望在导航 Controller 上调用此方法,对吗?)我只是想确保您的方法签名完全正确。如果不是(由于拼写错误、不正确的参数等),那么它肯定不会被调用。

第三:我会移动你的pushViewController:在您提供的其余代码之后调用。您不希望将 View 推送到屏幕上(以便用户可以看到它),然后让一堆屏幕上的值立即更改。设置您的 ivars 和 title首先属性,然后推送 View Controller 。这消除了任何奇怪的闪烁。

关于iphone - 推送 View Controller - 未调用 viewDidAppear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032237/

相关文章:

ios - 使用 useCameraDevices 交换相机时 iOS 7 崩溃

ios - 为什么我在推送一些 ViewController 后在 tableView 的顶部获得空间?

ios - Finder Preview 不显示 Mojave 下移动配置文件的详细信息

iphone - 在UIWebView中一一加载多个URL

ios - 不兼容的指针类型将 User* 发送到 UserProfile* 类型的参数

ios - 直接在自定义 Getter/Setter 中设置 NSUserDefaults

objective-c - 我可以使用 [FBDialogs presentOSIntegratedShareDialogModallyFrom] 通过 SDK 3.5 将图像发布到 facebook 吗?

iphone - 在应用程序内创建应用程序设置

iphone - 使用 iPhone 中的自定义按钮执行 MFMessageComposeViewController 中的按钮操作

objective-c - 使用可变参数列表创建 NSArray