iOS關於UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的傳遞頁面推送

來源:互聯網
上載者:User

標籤:

  • 關於UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的傳遞
  • 集合嵌套集合的操作 

 

  • 聲明

 

  • 兩個必須的的代理
  • 實現部分代碼

- (void)viewDidLoad

{

    [super viewDidLoad];

    // 建立一個TabView

    self.tabv = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];

    self.tabv.separatorColor = [UIColor blackColor];

    self.tabv.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"44W58PICRtX_1024.jpg"]];

 

    // 擷取資料來源

    self.arriOSclass = [NSMutableArray array];

    self.arriOSclass = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iOS_class" ofType:@"plist"]];

    

    // 指定代理和資料來源

    self.tabv.delegate = self;

    self.tabv.dataSource = self;

   

    // 指定重用儲存格的唯一標識:UITableView的唯一標識註冊UITableViewCell

    // - 重用cell而不是本身

    [self.tabv registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    

    // 添加到主視圖

    self.navigationItem.title = @"iOS_class";

    [self.view addSubview:self.tabv];

  

}

 

// 實現協議方法

// 確定顯示的數量(資料來源必須實現_1)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    // 選中集合

    return [self.arriOSclass[section] count];

}

 

// 擷取顯示的內容(資料來源必須實現_2)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 重用機制:儲存格容量固定,僅僅是更換內容(隊列)

    // 儲存一個唯一標識

    static NSString *cellIdentity = @"cell";

    // 根據tableView的唯一標識和資料分配UITableViewCell

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentity forIndexPath:indexPath];

    // 在UITableViewCell內顯示UITableView對應下標內容

    

    // 使用簡寫

//    cell.textLabel.text = [[self.arriOSclass objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];

    // 選中部分是一個集合,它的row才是字串

    cell.textLabel.text = self.arriOSclass[indexPath.section][indexPath.row];

 

    return cell;

}

 

// 代理方法:為資料分組(TabView的style為group)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return self.arriOSclass.count;

}

 

// 為分組命名

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"第%lu組", section+1];

}

 

// 為選中資料添加彈窗

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 先選擇部分(下標)再選擇個體(下標)

    NSString *info = self.arriOSclass[indexPath.section][indexPath.row]

    ;

    // 建立彈窗

    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:info message:@"確認修改嗎" preferredStyle:UIAlertControllerStyleAlert];

    // 添加確認動作

    UIAlertAction *alercAOK = [UIAlertAction actionWithTitle:@"確認" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)

    {

        // 推送到下一頁修改值

        PPViewController *ppVc = [PPViewController new];

        [self.navigationController pushViewController:ppVc animated:YES];

        // 沒有轉場效果?(模態視圖具有)

        ppVc.modalTransitionStyle = UIModalTransitionStylePartialCurl;

        // 傳遞資料來源中需要修改的索引過去

        ppVc.name = info;

        // 修改後返回該值:選擇block進行操作

        ppVc.ppblock = ^(NSString *name)

        {

            // 方法的回調:這個方法實際是在第二頁面修改後才會調用該block

 

            // 修改數組的地址

            self.arriOSclass[indexPath.section][indexPath.row] = name;

            // 修改後重新整理資料返回時才能正常顯示

            [self.tabv reloadData];

        };

    }];

    

    // 添加取消動作

    UIAlertAction *alertACancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];

 

    // 動作添加到UIAlertController

    [alertC addAction:alercAOK];

    [alertC addAction:alertACancel];

    // UIAlertController添加到當前控制器:即self

    [self presentViewController:alertC animated:YES completion:nil];

    

    

}

 

  • 傳值詳細解釋

 

 

  • 傳值頁面的聲明

 

  • 傳值也面的實現

 

iOS關於UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的傳遞頁面推送

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.