无法将分段控制连接到其IBOutlet

时间:2013-02-11 18:38:48

标签: iphone ios objective-c xcode4 ios6

我在界面构建器中创建了一个分段控件。

在我的ViewController.h中:

@interface ViewController : UIViewController <MKMapViewDelegate>
@property IBOutlet UISegmentedControl *Segment;
- (IBAction)switchMode:(id)sender;
@end

我能做的是将分段控件与IBAction连接,但我无法将其与IBOutlet连接!

3 个答案:

答案 0 :(得分:6)

  • 将分段控件添加到nib / Storyboard
  • 将以下代码添加到.h

@property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;

  • 在storyboard或xib中,确保文件所有者与您编写插座的类具有相同的类名
  • 右键单击segmantControl,出现一个带有出口和操作的窗口
  • 点击并拖动引用插座并将其放在 filesowner 上,会出现一个新的弹出窗口,其中包含用代码编写的插座选择它。

已建立连接

答案 1 :(得分:0)

您忘记编写属性参数,如下面的代码更正

@property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;

之后在.m文件中合成此属性,如下所示

@Synthesize Segment;

答案 2 :(得分:0)

看来,通过某些xCode更新,您无法再将某些插座连接到.h。你可以很好地将它连接到.m中:

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISegmentedControl *mySegmentedController;
@end

我会阅读一些文档,看看它何时发生了变化。此外,没有理由将此属性连接到您的公共接口(因此不再允许它)。只有该类的View Controller才能控制它。