1

当我想将 UIPicker 分配为 UITextField 的 inputView 时遇到问题。它显示错误“分配给只读属性”。请帮忙,因为我认为这与财产合成无关。

我在下面添加了我的代码:

@interface DriverWaitingDetails : UIViewController<UITextFieldDelegate,UIPickerViewDataSource, UIPickerViewDelegate>
{

IBOutlet UILabel *baseLabel;
IBOutlet UITableView *driverTableView;
IBOutlet UIPickerView *basePicker;
}

 @property(nonatomic, retain) IBOutlet UIPickerView *basePicker;
 @property(nonatomic,retain)IBOutlet UILabel *baseLabel;
 @property(nonatomic,retain)IBOutlet UITableView *driverTableView;


@end

实施代码:-

-(void)viewDidLoad
{

basePicker=[[UIPickerView alloc] initWithFrame:CGRectMake(0,100,320, 500)];
self.navigationItem.title=@"Driver Table";
baseLabel.userInteractionEnabled = YES;
basePicker.delegate = self;
basePicker.dataSource = self;
[basePicker setShowsSelectionIndicator:YES];
baseLabel.inputView=nil;
[super viewDidLoad];    
}

附截图:- UITextField 错误图像

4

2 回答 2

5

您正在设置的输入视图UILabel。您将 baseLabel 声明为UILabelnot UITextField

IBOutlet UILabel *baseLabel;
于 2012-11-08T08:33:26.067 回答
0

你已经声明

IBOutlet UILabel *baseLabel;

UILabel 继承自UIView : UIResponder : NSObject,属性定义在UIResponder

@property (readonly, retain) UIView *inputView

由于该属性inputView是只读的,因此您不能为其分配任何值。

于 2012-11-08T08:45:48.167 回答