你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS開發學習之#提醒處理#(1)響應提醒視圖

iOS開發學習之#提醒處理#(1)響應提醒視圖

編輯:IOS開發綜合

在這裡我用到了視圖庫裡的Navigation Controller導航控制器。

提醒操作主要用到了UIAlertviewDelegate協議中的alertView:clickButtonAtIndex:方法實現,其語法形式如下:

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

(UIAlertView *)alertView用來指定警告視圖中包含的按鈕,(NSInteger)buttonIndex用來指定點擊的按鈕的索引

核心代碼如下:

TableViewController.h

#import 

@interface TableViewController : UITableViewController{
    NSMutableArray *a;
}

- (IBAction)aa:(id)sender;

- (IBAction)bb:(id)sender;
@end

TableViewController.m部分代碼片段

- (IBAction)aa:(id)sender {
    UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"編輯" message:@"請選擇項目" delegate:self cancelButtonTitle:@"Canel" otherButtonTitles:@"Add",@"Delete", nil];
    [a show];
}

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *b = [alertView buttonTitleAtIndex:buttonIndex];
    if ([b isEqualToString:@"Delete"]) {
        [self setEditing:YES];
    }
    if ([b isEqualToString:@"Add"]) {
       UIAlertView *a1 = [[UIAlertView alloc]initWithTitle:@"添加" message:@"確定要添加聯系人嗎" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [a1 show];
    }
}

- (IBAction)bb:(id)sender {
    [self setEditing:NO];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [a removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}



  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved