问题描述
||
我正在学习开发iOS应用程序(我是Objective-C和Cocoa的新手),并且我在做这个非常简单的示例练习(两个标签显示在Label中按下了Left或Right按钮)。
我只创建了一个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
好吧,就是这样,希望您能为我提供帮助,这可能是一个愚蠢的错误,但是我已经浏览了很多,但找不到解决方案。
解决方法
您的财产声明应如下所示
@property (retain,nonatomic) IBOutlet UILabel *statusText;