Это то, что я делаю, аналогично настройкам> Общие> Международные> Языковая таблица в iPhone / iPod.
Пользователь может коснуться строки, и появится галочка. Вид закрывается при нажатии «Готово» или «Отмена».
Сначала создайте UITableViewController
, который будет отображать ваши параметры. В верхней части панели инструментов есть кнопка «Отмена» и «Готово». Также есть эти свойства:
SEL selector; // will hold the selector to be invoked when the user taps the Done button
id target; // target for the selector
NSUInteger selectedRow; // hold the last selected row
Это представление будет отображаться методом presentModalViewController:animated:
, поэтому оно отображается в нижней части экрана. Вы можете представить его любым другим способом, но он кажется стандартным для всех приложений iPhone.
Перед представлением вида установите target
и selector
, чтобы метод вызывался, когда пользователь нажимал кнопку «Готово».
Теперь в только что созданном UITableViewController you can implement the the
tableView: didSelectRowAtIndexPath: `method as:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark; // show checkmark
[cell setSelected:NO animated:YES]; // deselect row so it doesn't remain selected
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedRow inSection:0]];
cell.accessoryType = UITableViewCellAccessoryNone; // remove check from previously selected row
selectedRow = indexPath.row; // remember the newly selected row
}
Также реализуйте методы отмены и выполнения для кнопок панели инструментов:
- (IBAction)done:(UIBarButtonItem *)item
{
[target performSelector:selector withObject:[stringArray objectAtIndex:selectedRow]];
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)cancel:(UIBarButtonItem *)item
{
[self dismissModalViewControllerAnimated:YES];
}