2010-04-19 2 views
0

Я пытаюсь отправить переменную ActionSheet с помощью кнопки.Передача значений из UIButton в UIActionSheet

Я не могу использовать свойство тега, потому что его используют для чего-то другого.

Я объявил myIndexRow как переменный экземпляр и есть:

NSInteger myIndexRow = indexPath.row; 
    [deleteButton addTarget:self action:@selector(showDeleteSheet:) forControlEvents:UIControlEventTouchUpInside]; 

    deleteButton.myIndexRow = myIndexRow; 

, но я получаю «Запрос члена„myRow“что-то не структуры или объединения»

Там есть что-то очевидное я здесь отсутствует.

+0

Вышеуказанное не удалось. См. Ответ ниже для способа сделать это. –

ответ

1

Никогда не понял, что я ответил на мой собственный вопрос на SO, но здесь идет:

Доступ SuperView в SuperView и запрашивая раздел indexPath и свойства строк сделал трюк.

В цели кнопки:

-(void)showDeleteSheet:(id)sender { 

NSIndexPath *indexPath = [table indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; 

    NSInteger currentSection = indexPath.section; 
    NSInteger currentIndexRow = indexPath.row; 

    //form the actionSheet 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete this item?" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:@"Delete" 
               otherButtonTitles:nil];       
    actionSheet.tag = currentIndexRow; 
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 
    [actionSheet showInView:self.view]; 
    [actionSheet release]; 
} 

Тогда вниз в методе clickedButtonAtIndex в actionSheet, я получаю строку мне нужно:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if (buttonIndex == 0) 
     { ... doSomethingWith: actionSheet.tag } 
    else 
     { ... user pressed cancel } 
} 

Часть ответа был найден in another post and и остальные here

Смежные вопросы