2014-10-27 22 views
-2

我有一個UIAlertView在「UITableViewCellEditingStyleDelete」我試圖獲取所選單元格的行中的對象,但我找到了方法。Obj-C,獲取選定的行到UIAlertview clickedButtonAtIndex方法

這是我的代碼:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     confirmBlock = [[UIAlertView alloc] initWithTitle:@"Attention" message:[NSString stringWithFormat:@"Are you sure you want to block %@ ?", splitRow[1]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil]; 
     [confirmBlock show]; 
    } 

,並在用戶點擊選擇的選項之一:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
// here, how can I get the objectAtIndex of the selected row ? 

} 

我與標註的alertview,但它不是COS的objectAtIndex工作,試圖爲一個字符串。

回答

1

使用alertview.message並解析字符串以獲取數字 進行解析可能試試componentsSeparatedByString:使用「」(空格)並獲取返回數組的第二個最後一個索引,這將成爲消息中的行號。

或者你可以簡單地使用泰伯維的

`selectedRow 

財產

編輯:

但更可行的方法是設置在.h文件中一個對象:

NSInteger selectedRow; 

並在顯示alertView之前設置它,然後在clickedbuttonatindex f中獲取該值聯合

相關問題