iphone之推送 View Controller之未调用 viewDidAppear

kuangbin 阅读:83 2025-05-04 20:05:19 评论:0

我有这段代码来推送 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 。这消除了任何奇怪的闪烁。


标签:程序员
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号