Outlet不会出现在Interface Builder(Xcode 3)和Xcode4中

时间:2011-05-24 16:03:12

标签: iphone ios4 iboutlet outlet

我正在学习开发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

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

1 个答案:

答案 0 :(得分:2)

您的财产声明应如下所示

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