我想创建一个包含段控件和标签的应用程序,按下控件时更改标签。
我想使用“发件人”来获取段控件的值,但为什么它不起作用?
-(void)segmentControlIndexChanged:(id)sender
{
switch ([sender selectedIndex]) {
case 0:
label.text = @"Case Zero :)";
break;
case 1:
label.text = @"Happy New Year!";
break;
default:
label.text = @"Press a button:";
break;
}
}
其他麻烦:下面的代码导致:
-[ViewController segmentControlIndexChanged:]:无法识别的选择器发送到实例
//ViewController.h
@interface ViewController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UISegmentControl *segmentControl;
}
@property (retain, nonatomic) UILabel *label;
@property (retain, nonatomic) UISegmentControl *segmentControl;
-
//ViewController.m
-(IBAction)segmentControlIndexChanged
{
switch ([segmentControl selectedSegmentIndex]) {
case 0:
label.text = @"X'mas always come first :)";
break;
case 1:
label.text = @"Happy New Year!";
break;
default:
label.text = @"Press a button:";
break;
}
}