开发者

basic xcode iphone app not working, button clicks to change text?

开发者 https://www.devze.com 2023-03-15 04:44 出处:网络
I\'ve followed the tutorial below, it basically just tells you to create a button and a label. When you click the button the label should change to some text.

I've followed the tutorial below, it basically just tells you to create a button and a label. When you click the button the label should change to some text.

http://paulpeelen.com/2011/03/17/xcode-4-ios-4-3-hello-world/

It runs but it shows a blank screen. When you click the screen it goes blue like the entire page is a button. I think it's loading the mainwindow.xib fil开发者_JS百科e instead of the default ViewController.xib

Any ideas, I'm obviously missing something?

Thanks

EDIT

#import <UIKit/UIKit.h>

@interface fun_buttonViewController : UIViewController {
    UILabel *textLabel;

}

@property (nonatomic, retain) IBOutlet UILabel *textLabel;

- (IBAction)changeTheTextOfTheLabel;

@end

The implementation:

#import "fun_buttonViewController.h"

@implementation fun_buttonViewController

@synthesize textLabel;

- (void)dealloc
{
    [super dealloc];
    [textLabel release];
}

- (IBAction)changeTheTextOfTheLabel
{
    [textLabel setText:@"Hello, World!"];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end


You probaly made a simple mistake. I would go through the example again and see if you did anything diffrently.

If you post your code or upload your files somewhere I could take a look at it for you.

Its kind of hard to guess what the problem is without seeing what you actually did^^


It was as I suspected. It's not a code problem, since the code is fine. The tutorial is also perfectly fine. I thought it had to do with the XIB, and when I looked into there this is what I saw:

In your MainWindow.xib, you had a button loading from the ViewController. Why? I don't know. It might have been placed there by accident. Here's a screenshot of what I mean:

basic xcode iphone app not working, button clicks to change text?

The left view is from your view controller. See the UIButton loading in the ViewController? It is blocking the rest of the view. Just delete the button that's loading OVER your view, and it works perfectly. The view hierarchy, was essentially blocked by that massive extraneous button.


It could be anything from your XIB (most likely) or from your app delegate.

Are you sure you connected the buttons properly? Send us your code/zip of the project so far.

0

精彩评论

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

关注公众号