все. В настоящее время я пытаюсь понять, как добавить UIAlertView, который будет запрашивать у пользователя, хотят ли они удалить все элементы или только один из списка покупок.UIAlertView для удаления строки из контроллера UITableView
У меня возникли проблемы с этим, так как из всего, что я нашел, мне нужно использовать didDismissButtonWithIndex, чтобы выяснить, какая кнопка была нажата.
Любые идеи?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
for (myData *item in self.itemData)
{
if(item.count > 1)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"delete how many?" delegate:self cancelButtonTitle:@"1" otherButtonTitles:@"All", nil];
[alert show];
}
else
{
int index = indexPath.row;
[self.itemData removeObjectAtIndex:index];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0) {
//selected item's count--
}
if(buttonIndex == 1) {
//selected item deleted completely
}
}
что именно ваша проблема? с помощью 'alertView: didDismissWithButtonIndex:' является прекрасным подходом :), если вы хотите быть немного понятнее, что означают индексы, вы можете объявить их как константы, чтобы дать им некоторую дополнительную семантику. – nburk
ru нужен метод alert в методе didselectatrowatindexpath или любой кнопки метод действия –
@nburk Я знаю, что didDismissWithButtonIndex: это правильный способ обойти это. Я просто не уверен, что я удалю элемент оттуда без tableView commiEditingStyle. – Josh