1

我有一个分段控件,当触摸已选择 selectedSegmentIndex 的日志时。但是它输出nullself.sessoField.text;

知道如何解决这个问题吗?

谢谢

这是来自以下内容的控制台输出:

2013-10-24 11:00:11.131 [3628:60b] gender is (null) 1
2013-10-24 11:00:40.179 [3628:60b] gender is (null) 0
2013-10-24 11:00:41.546 [3628:60b] gender is (null) 1

.

- (IBAction)genderSelectButton:(id)sender {

    if (self.segmentedControlGender.selectedSegmentIndex == 0) {
        self.sessoField.text = @"m";
        NSLog(@"gender is %@ %d",self.sessoField.text,self.segmentedControlGender.selectedSegmentIndex);

    } else if(self.segmentedControlGender.selectedSegmentIndex == 1) {
        self.sessoField.text = @"f";
        NSLog(@"gender is %@ %d",self.sessoField.text,self.segmentedControlGender.selectedSegmentIndex);

    }
}

sessoField 已在 .h 中声明为:

@property (nonatomic, weak) IBOutlet UITextField * sessoField;
4

2 回答 2

1

首先检查您的文本字段是否为零,然后尝试这样:-

NSLog(@"gender is %@ %d",self.sessoField.text,self.segmentedControlGender.selectedSegmentIndex);
于 2013-10-24T10:15:34.090 回答
-1
@property (nonatomic, weak) IBOutlet UITextField * sessoField;

should be 

@property (nonatomic, strong) IBOutlet UITextField * sessoField;
于 2013-10-24T10:21:22.803 回答