我正在使用 CPPicker 在我的应用程序中实现水平选择器,并且我正在使用标签来确定我正在谈论的两个选择器中的哪一个。
// Picker creation
CPPickerView *pickerView = [[CPPickerView alloc] initWithFrame:CGRectMake(100, 5, 150, 40)];
pickerView.dataSource = self;
pickerView.delegate = self;
pickerView.peekInset = UIEdgeInsetsMake(0, 40, 0, 40);
[pickerView reloadData];
pickerView.showGlass = YES;
[cell addSubview:pickerView];
if (indexPath.section == 0) {
pickerView.tag = 0;
}
else if (indexPath.section == 1) {
pickerView.tag = 1;
}
return cell;
然后稍后,我检查标签以指定pickerView 的标题。但它只为标签读取 0,因此两个选择器具有相同的值。
- (NSString *)pickerView:(CPPickerView *)pickerView titleForItem:(NSInteger)item {
NSString *title = nil;
if (pickerView.tag == 0) {
title = [NSString stringWithFormat:@"%d", (200 + (item * 20))];
}
else if (pickerView.tag == 1) {
title = [NSString stringWithFormat:@"%d", item + 1];
}
return title;
}
我在这里做错了什么?