使用self.UISegmentedControl.selectedSegmentIndex时如何修复“信号SIGABRT”

时间:2019-05-26 00:41:14

标签: objective-c uisegmentedcontrol sigabrt

每次我使用"self.SegControl.selectedSegmentIndex"时,都会在以下SIGABRT中收到code信号:

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil,     NSStringFromClass([AppDelegate class]));// signal SIGABRT
    }
}

我试图找到self.SegControl.selectedSegmentIndex的值:

long a=self.SegControl.selectedSegmentIndex;

但是,我发现我什至不能使用self.SegControl.selectedSegmentIndex

...
@property (weak, nonatomic) IBOutlet UISegmentedControl *SegControl;
...
- (IBAction)Button:(id)sender {
NSMutableString *str=[NSMutableString new];
if(self.SegControl.selectedSegmentIndex==0){
    [str appendString:@"unit 2"];
}
else if(self.SegControl.selectedSegmentIndex==1){
    [str appendString:@"unit 3"];
}
else if(self.SegControl.selectedSegmentIndex==2){
    [str appendString:@"unit 4"];
}
self.Output.text=str;
}
...

我想获取self.SegControl.selectedSegmentIndex的输出。我想让我的程序知道选择了哪个段。 请帮帮我! 谢谢!

1 个答案:

答案 0 :(得分:0)

在if语句时是否选择了任何索引?

在情节提要中,您是否有任何选定的索引作为默认值?有一个复选框,您可以在其中设置默认选定索引的行为。或者,您应该在if语句之前以编程方式进行操作。

enter image description here