确保您有IB挑选器对象,如果这是你使用的是什么,然后创建一个IBOutlet参考,并将其连接到IB的对象。我将我的pickerView设置为隐藏在IB中,并在需要时使其可见。否则,您可以根据需要简单地实例化一个。
在您的didSelectRowAtIndexPath中,您可以尝试下面的代码,看看会发生什么。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (**your cell/section selection logic here**) {
[self.view endEditing:YES]; // resign firstResponder if you have any text fields so the keyboard doesn't get in the way
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; // Scroll your row to the top so the user can actually see the row when interacting with the pickerView
// Pickerview setup
[self.typePicker setCenter:CGPointMake(150, 500)]; // place the pickerView outside the screen boundaries
[self.typePicker setHidden:NO]; // set it to visible and then animate it to slide up
[UIView beginAnimations:@"slideIn" context:nil];
[self.typePicker setCenter:CGPointMake(150, 250)];
[UIView commitAnimations];
}
}
之后,你需要的,如果你想更新的选择器视图的选择更改您的电池的标签来实现你pickerView:didSelectRow:
方法...
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Your code to get the current table view cell and update it with the data from your pickerView
}
确保您的viewController被声明为代表对于tableView <UITableViewDelegate>
以及对于pickerView`'
这应该给你一个良好的开端。让我知道,如果你有任何问题,等等
干杯, 罗格
来源
2011-02-17 05:14:04
Rog
没有人会下载dateCell例子只是为了回答你的问题,甚至不是我。所以用实际代码替换// Date拾取器的东西。 – 2011-02-17 05:48:03