这是我的代码
class.h
.......
{
NSInteger selectedRow;
}
@property (nonatomic) NSInteger selectedRow;
.......
classs.m
@synthesize selectedRow = _selectedRow;
.......
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 150, 280, 100)];
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[self.view addSubview:picker];
self.selectedRow = [picker selectedRowInComponent:0];
按下按钮时,会调用选择器狗
-(void)dbg
{
NSLog(@"%d", self.selectedRow) -- RESULT 0
NSLOg(@"%@", self.selectedRow) -- RESULT null
}
我想念的是什么?
答案 0 :(得分:0)
NSLog(@"%@", …)
打印对象,但NSInteger是基本类型。第一个NSLog应该可以正常工作。
您必须实施选择器的委托,尤其是pickerView:didSelectRow:inComponent:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.selectedRow = row;
}
答案 1 :(得分:0)