In the Interface Builder, I've added an image and connected it to the File's Owner (to the imageFlag variable).
The image appears when the UIViewController is displayed. However, when I try to change the image, it fails:
Code:
UIImage *image = [UIImage imageNamed:@"USA.gif"];
assert( image != nil ); // This image is **not** nil.
[imageFlag setImage:image];
assert( self.imageFlag != nil ); The imageFlag var **is** nil here.
After hours of inspecting, I'm stumped. I have several other controls on this UIViewController that were set up similarly and their contents can be changed from within the code (although they are all UILabels rather than UIImageViews). I've also have a custom table cell setup elsewhere in the app that uses a similar technique to change the image that does work. I can't figure out what I'm doing wrong...
I don't see why that wouldn't work, unless you did not connect up the outlets correctly. Are you able to do anything to the image view, like changing its size? If you can't do anything to it, then you probably didn't connect it correctly.
In the Interface Builder, I've added an image and connected it to the File's Owner (to the imageFlag variable).
The image appears when the UIViewController is displayed. However, when I try to change the image, it fails:
Code:
UIImage *image = [UIImage imageNamed:@"USA.gif"];
assert( image != nil ); // This image is **not** nil.
[imageFlag setImage:image];
assert( self.imageFlag != nil ); The imageFlag var **is** nil here.
After hours of inspecting, I'm stumped. I have several other controls on this UIViewController that were set up similarly and their contents can be changed from within the code (although they are all UILabels rather than UIImageViews). I've also have a custom table cell setup elsewhere in the app that uses a similar technique to change the image that does work. I can't figure out what I'm doing wrong...
Ideas? Help? Thanks!
I think Kelvin is on to something. If the outlet to imageFlag is not connected, imageFlag would be bank, and the setImage call would be "dropped on the floor".
Set a breakpoint on the setImage line in the debugger, and make sure imageFlag is not nil.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I don't see why that wouldn't work, unless you did not connect up the outlets correctly. Are you able to do anything to the image view, like changing its size? If you can't do anything to it, then you probably didn't connect it correctly.
Yeah, per your and Ducan's comments, it wasn't set up correctly. Seeing that imageFlag was nil was the key. After 20 years using C++ on that other operating system, I'm struggling with the XCode/Interface interface. Thanks for the help, guys.
Yeah, per your and Ducan's comments, it wasn't set up correctly. Seeing that imageFlag was nil was the key. After 20 years using C++ on that other operating system, I'm struggling with the XCode/Interface interface. Thanks for the help, guys.
It took me a while to get my head around the idea that sending a message to a nil object pointer is perfectly ok. In most other languages this causes a crash, but it's perfectly okay in Objective C.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
It took me a while to get my head around the idea that sending a message to a nil object pointer is perfectly ok. In most other languages this causes a crash, but it's perfectly okay in Objective C.
It took me a while to get my head around the idea that sending a message to a nil object pointer is perfectly ok. In most other languages this causes a crash, but it's perfectly okay in Objective C.
Yeah, I am used to the compiler (and language) making sure I'm doing what I intended to do (e.g., not passing a message to a nil pointer, not calling a member function that doesn't exist, etc). And since I don't know what I'm doing on this platform, it's a little more difficult to learn by trial-and-error. That said, I am making progress and appreciate the help that folks (like you) give to newbies on the forums. Thanks again.