確保您有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