开发者

Is someone willing to look at my (very small) project on DropBox and give me a hint on my IB connections?

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 initializati开发者_Go百科ons 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


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.


I have downloaded it.

Is someone willing to look at my (very small) project on DropBox and give me a hint on my IB connections?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜