2016-02-02 13 views

回答

1

簡而言之,您可以基於單擊單元格顯示警報視圖。所以

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if(indexPath.row == 0) { //Change 0 to the row you want 
     [self showAlertView]; 
    } 
} 

然後,在一個單獨的函數

-(void)showAlertView { 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"YOUR TITLE" 
                     message:@"AND A MESSAGE OF YOUR ALERT" 
                     preferredStyle:UIAlertControllerStyleAlert]; 
    //We add buttons to the alert controller by creating UIAlertActions: 
    UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"YOUR BUTTON TITLE" 
                style:UIAlertActionStyleDefault 
               handler:nil]; //You can use a block here to handle a press on this button 
    [alertController addAction:actionOk]; 
    [self presentViewController:alertController animated:YES completion:nil]; 
} 

編輯*********

基於您的評論

如果你想顯示警報基於在cell標識符上,你可以在didSelectRowAtIndexPath方法中使用類似這樣的東西。

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

if([cell.reuseIdentifier isEqualToString:@"CELLIDENTIFIER"]){ 
    [self showAlertView]; 
} 
+0

感謝你的幫助,首先,但我想知道如果我想使用標識的方式來顯示當我點擊特定小區的alertView什麼,比如我單擊單元格的標識是「showAlertView」?謝謝再次。 –

+0

,完美的作品,thx –

+0

沒問題。如果你的需要你可以接受這個答案作爲解決方案。謝謝 – Devster101