0
我正在使用UIPickerView
並希望該部分與上次使用時相同。我看了一下蘋果的文檔,但沒有看到有關設置章節的任何內容。無法弄清楚如何設置UIPickerView的起始值
我的代碼
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Initialize Data
_pickerData = @[@"I", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];
// Connect data
picker.dataSource = self;
picker.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)aOk:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
// store data
int i=0;
i=[picker selectedRowInComponent:1]*10;
i+=[picker selectedRowInComponent:1];
}
- (IBAction)aCancel:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
// The number of columns of data
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
// The number of rows of data
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
// compment contains the col number
return _pickerData.count;
}
// The data to return for the row and component (column) that's being passed in
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return _pickerData[row];
}
// Catpure the picker view selection
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// This method is triggered whenever the user makes a change to the picker selection.
// The parameter named row and component represents what was selected.
}
@end
我無法得到它的工作,只是停留在把一個破發點上的if語句開始現在的位置代碼 –
。 ..即如果(lastSelectedRow)。 lastSelectedRow變量是否有你正在尋找的索引?另外,你是否存儲最後選擇的索引? –