First: You definitely don't want to be calling any of the standard viewWillLoad viewDidLoad viewWillAppear etc. methods manually. Let the OS do it for you.
Up vote 0 down vote favorite share g+ share fb share tw.
I have this piece of code to push a 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; But the delegate method viewDidAppear does not get called when the productView appears. I looked up the problem on google and theres a lot of different solutions, none of which I could apply to my problem.. I had a similar problem in a previous solution but I got around it by manually calling viewDidApear in the viewDidLoad method.
Unfortunately in this case I can't do that as viewDidLoad is called only once (on the first push). Does anyone know how to fix this? Thanks, Jack Nutkins EDIT: Here is the viewDidAppear method in the productView (and selector): - (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 } iphone objective-c ios uinavigationcontroller modalviewcontroller link|improve this question edited Nov 7 '11 at 3:06 asked Nov 7 '11 at 2:44Jack Nutkins28411 96% accept rate.
Well is your self. ProductView a view or a view controller? Because the viewDidAppear is only called if your class is a view controller!
– Wesso Nov 7 '11 at 2:47 Sorry yes, I should have mentioned that, its a view controller. – Jack Nutkins Nov 7 '11 at 3:09.
First: You definitely don't want to be calling any of the standard viewWillLoad, viewDidLoad, viewWillAppear, etc. methods manually. Let the OS do it for you. Second: Can you show us how your viewDidAppear method is implemented in your self.
ProductView instance? (Just a hunch, you're not expecting this method to be called on your navigation controller, right? ) I just want to make sure your method signature is exactly correct.
If it's not (due to a mispelling, improper args, etc.) then it definitely won't be called. Third: I would move your pushViewController: call to after the rest of the code you provided. You don't want the view to be pushed on the screen (so the user can see it) and then have a bunch of on-screen values immediately change.
Set your ivars and title property first, then push the view controller. This eliminates any weird flickering.
Pushing the controller at the end causes the text not to be set in the labels on the first push, but in corresponding pushes works fine. Off-topic, but would it be better for me to set the values of NSStrings rather than set the text values of the labels? Then set the label values in the pushed controllers viewDidAppear?
Assuming I can get viewDidAppear to trigger.. – Jack Nutkins Nov 7 '11 at 3:13 You generally don't want to access the UI components of the view controller from outside the view controller itself. In some cases it's acceptable, but is generally bad practice. Your navigation controller (or whatever is preparing the view controller) shouldn't know how the information is being displayed.
If your layout/style of the view controller changes down the road, callers shouldn't have to care. You should be providing information to the view controller, not UI component-specific method calls. – craig Nov 7 '11 at 3:35.
I solved it, though it doesn't seem conventional, can't believe I didn't try it earlier : I put this line : self. ProductView viewDidAppear:YES; Underneath : // Setup the animation self. NavigationController pushViewController:self.
ProductView animated:YES; I also moved the code to set the labels text to run before the above line. (As well as changing my code to send strings to the pushed controller rather that accessing its UI elements. ) Thanks for everyones help, Jack.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.