【问题标题】:Outlet doesn't show up in Interface Builder (Xcode 3) nor Xcode4Outlet 没有出现在 Interface Builder (Xcode 3) 和 Xcode4 中
【发布时间】:2023-03-24 13:59:01
【问题描述】:

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

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

【问题讨论】:

  • @property (retain, nonatomic) IBOutlet UILabel *statusText;
  • 您检查过 FilesOwner 属性设置是否正确吗?为此,在 Xcode4 的界面构建器中打开您的 ViewController,在左侧选择 Files's Owner,然后转到右侧的第三个选项卡(Identity Inspector)。类喊是 Hola_MundoViewController
  • 看起来缺少 IBOutlet 是造成这种情况的原因(当您使用旧文档学习 xD 时会发生这种情况),谢谢您,TheBlack。
  • @TheBlack:请将其作为答案发布,以便 OP 将其标记为已解决。
  • ésar González 不客气 :) 请接受下面 arclights 的回答。

标签: iphone ios4 iboutlet outlet


【解决方案1】:

您的属性声明应如下所示

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

【讨论】:

    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多