views:

44

answers:

2

Hello,

I am working on a very small (one view) iPhone app (iOS 4.0.2 on Xcode 3.2.3) and I think that I am missing something in how I have made my IBOutlet and IBAction connections in IB. I am hoping that one (or several) of you kind folks out in the ether will be willing to connect to my dropbox and dl the project and give me a hint as to where I have screwed up?

I have been working on this for a few days (well a bunch of hours over about three days) and have not found my error yet....

::sigh::

Is anyone game for this? Here is the link if you are: http://dl.dropbox.com/u/5271440/picChoice.zip

ABOUT THE APP:

When run, this app should throw up a window on the simulator which contains a UIImageView, UILabel and a UISegmentedControl. The UIImageView should display a default image, the UILabel should display a default string, and when any segment is touched on the UISegmentedControl, the image and label should change accordingly.

I had this working on the simulator for awhile, but when I loaded it on my iPhone, I found a bunch of crashers (bad array initializations and pointer problems. I am learning....)

After seemingly 'fixing' the crashing errors, I seem to have broken my connections never to function properly again....

Any and all assistance is sincerely appreciated!

Kind regards,

Steve O'Sullivan

A: 

Hi,

I have downloaded it. alt text

You have open IB, in the documents area you can right click on the view, wire up the "New Referencing Outlet" to the files owner, when you drop it there it will give you the option of view.

This sometimes happens and all things break if this does not work.

Dont forget to mark the questions as the accepted answer (thanks).

John.

John Ballinger
Hi John, thanks for your suggestion! I am still working on this, but the question is still open. :)
Sosullivan
+1  A: 

You have more issues than just the view not appearing. Once you follow John's answer you still get nothing other than a label that says "Label" and a segmented control that affects nothing. In order to get the initial look to be correct you must first remove three lines of code:

txtLabel = [[UILabel alloc] init];
imageView = [[UIImageView alloc] init];
seg = [[UISegmentedControl alloc] init];

The runtime takes care of these for you. Once they are removed you get the happy face and correct text in the label. At this point you get blank images and text if you select a segment. Right now you should make the changes thus far add a breakpoint at your -(IBAction)segmentedControlValueChanged method, and then build and debug. Click on a segment and then look in the debugger under self, notice that both imageArray and txtArray have 0 objects. to fix this you need to make a few more changes. Since you don't really make any changes to either array after creation you can make them regular NSArrays and declare them as properties (don't forget @synthesize as well). To keep the rewriting of your existing code to a minimum make your viewDidLoad look like this:

- (void)viewDidLoad
{
//  txtLabel = [[UILabel alloc] init];
//  imageView = [[UIImageView alloc] init];
//  seg = [[UISegmentedControl alloc] init];
    NSMutableArray *anArray = [[NSMutableArray alloc] init];

    [anArray addObject:[UIImage imageNamed:@"jupiter2.JPG"]];
    [anArray addObject:[UIImage imageNamed:@"waffles?.JPG"]];
    [anArray addObject:[UIImage imageNamed:@"enterprise.JPG"]];
    [anArray addObject:[UIImage imageNamed:@"wrunning.JPG"]];
    [anArray addObject:[UIImage imageNamed:@"ApolloCSM.JPG"]];
    self.imageArray = [anArray copy];

    [anArray removeAllObjects];
    NSString *myStr = [[NSString alloc] initWithString:@"Jupiter II"]; 
    [anArray addObject: myStr];
    [myStr release];

    myStr = [[NSString alloc] initWithString:@"Could this be OUR Waffles?"]; 
    [anArray addObject: myStr];
    [myStr release];

    myStr = [[NSString alloc] initWithString:@"USS Enterprise NCC-1701"]; 
    [anArray addObject: myStr];
    [myStr release];

    myStr = [[NSString alloc] initWithString:@"A Woman Running"]; 
    [anArray addObject: myStr];
    [myStr release];

    myStr = [[NSString alloc] initWithString:@"Apollo Command and Service Modules"]; 
    [anArray addObject: myStr];
    [myStr release];

    self.txtArray = [anArray copy];
    [anArray release];
    imageView.image = [UIImage imageNamed:@"happy-face.JPG"];
    txtLabel.text = @"Hi there!";

    [imageView release];

    [super viewDidLoad];
}

You could also use the NSArray method arrayWithObjects: to shorten the method and alloc fewer objects along the way.

Hello user427302:I think that I have implemented you suggestions correctly, and when I run the modified app on my actual device, it crashes the debugger. Is there any way that we can converse about this?
Sosullivan
If it really is the debugger crashing and not the debugger taking over because you got something like "EXC_BAD_ACCESS" then I would add liberal amounts of `NSLog` statements to track down what happens just before the crash. Try adding logs to the start and end of each method first. Then when you find a method that doesn't finish add a log in the middle and just keep cutting in half until you find the trouble maker.