0

我正在学习开发 iOS 应用程序(我是 Objective-C 和 Cocoa 的新手),我正在做这个非常简单的示例练习(在标签中按下两个按钮,显示左或右按钮)。

我只是创建了一个 IBOutlet 和几行代码,保存了两个 AppViewController 文件,当尝试将 IBOutlet 与 Interface Builder 中的实际标签连接时,插座不显示。

我正在使用 iOS SDK 4.3

这是源代码:

//
//  BotonViewController.h
//  Boton
//
//  Created by Abu on 5/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface Hola_MundoViewController : UIViewController {

IBOutlet UILabel *statusText; 

}

@property (retain, nonatomic) UILabel *statusText;

-(IBAction)buttonPressed: (id)sender;

@end

//
//  BotonViewController.m
//  Boton
//
//  Created by Abu on 5/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BotonViewController.h"

@implementation Hola_MundoViewController
@synthesize statusText;

-(IBAction)buttonPressed: (id)sender
{
NSString *title = [sender titleForState:UIControlStateNormal];
NSString *newText = [[NSString alloc] initWithFormat:
                     @"%@ button pressed.", title];
statusText.text = newText;
[newText release];
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:         (UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (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.
}

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


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

@end

嗯,就是这样,希望你能帮助我,可能是一个愚蠢的错误,但我浏览了很多,我找不到解决方案。

4

1 回答 1

2

您的属性声明应如下所示

@property (retain, nonatomic) IBOutlet UILabel *statusText;
于 2011-05-24T17:26:37.690 回答