<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                AJ分享,必須精品 ### 先看效果圖 ![這里寫圖片描述](https://box.kancloud.cn/2016-03-16_56e8faece3910.jpg "") ![這里寫圖片描述](https://box.kancloud.cn/2016-03-16_56e8faed06f2f.jpg "") ![這里寫圖片描述](https://box.kancloud.cn/2016-03-16_56e8faed24210.jpg "") ![這里寫圖片描述](https://box.kancloud.cn/2016-03-16_56e8faed3f844.jpg "") ### 代碼 ~~~ // // Created by apple on 14-8-19. // Copyright (c) 2014年 itcast. All rights reserved. // #import "HMViewController.h" @interface HMViewController () <UITableViewDataSource, UITableViewDelegate> /** 數據列表 */ @property (nonatomic, strong) NSMutableArray *dataList; @property (nonatomic, strong) UITableView *tableView; @end @implementation HMViewController - (UITableView *)tableView { if (_tableView == nil) { _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; _tableView.dataSource = self; _tableView.delegate = self; [self.view addSubview:_tableView]; } return _tableView; } - (NSMutableArray *)dataList { if (_dataList == nil) { _dataList = [NSMutableArray arrayWithObjects:@"貓貓1號", @"貓貓1號", @"貓貓2號", @"貓貓3號", @"貓貓4號", @"貓貓5號",@"貓貓6號", @"貓貓7號", @"貓貓8號",@"貓貓9號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",@"貓貓1號", @"貓貓1號", @"貓貓1號",nil]; } return _dataList; } - (void)viewDidLoad { [super viewDidLoad]; [self tableView]; // 開始編輯,一旦editing == YES就默認開啟刪除模式 self.tableView.editing = YES; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } // 設置表格 cell.textLabel.text = self.dataList[indexPath.row]; return cell; } // 只要實現了此方法,就能夠支持手勢拖拽刪除了,刪除需要自己干! /** UITableViewCellEditingStyleNone, UITableViewCellEditingStyleDelete, 刪除 UITableViewCellEditingStyleInsert 添加 */ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSLog(@"要刪除"); // MVC => 數據是保存在模型中 // 1. 刪除self.dataList中indexPath對應的數據 [self.dataList removeObjectAtIndex:indexPath.row]; NSLog(@"%@", self.dataList); // 2. 刷新表格(重新加載數據) // 重新加載所有數據 // [self.tableView reloadData]; // deleteRowsAtIndexPaths讓表格控件動畫刪除指定的行 [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { NSLog(@"要添加數據"); // 1. 向數組添加數據 [self.dataList insertObject:@"王小二" atIndex:indexPath.row + 1]; // 2. 刷新表格 // [self.tableView reloadData]; // insertRowsAtIndexPaths讓表格控件動畫在指定indexPath添加指定行 // 新建一個indexPath NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; [self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationMiddle]; } } // 只要實現此方法,就可以顯示拖動控件 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { // 界面數據UITableView已經完成了 // 調整數據即可 // [self.dataList exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row]; // 1. 將源從數組中取出 id source = self.dataList[sourceIndexPath.row]; // 2. 將源從數組中刪除 [self.dataList removeObjectAtIndex:sourceIndexPath.row]; NSLog(@"%@", self.dataList); // 3. 將源插入到數組中的目標位置 [self.dataList insertObject:source atIndex:destinationIndexPath.row]; NSLog(@"%@", self.dataList); } #pragma mark - 代理方法 // 返回編輯樣式,如果沒有實現此方法,默認都是刪除 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { // if (indexPath.row % 2) { // return UITableViewCellEditingStyleInsert; // } else { // return UITableViewCellEditingStyleDelete; // } return UITableViewCellEditingStyleInsert; } @end ~~~ ### UITableView支持刪除手勢 只要實現了此方法,就能夠支持手勢拖拽刪除了,刪除需要自己干! ~~~ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath ~~~ UITableViewCellEditingStyleNone, 沒效果 UITableViewCellEditingStyleDelete, 刪除 UITableViewCellEditingStyleInsert 添加 刪除中要做的: 重新加載數據時候用[self.tableView reloadData];會效率低下 ~~~ // MVC => 數據是保存在模型中 // 1. 刪除self.dataList中indexPath對應的數據 [self.dataList removeObjectAtIndex:indexPath.row]; NSLog(@"%@", self.dataList); // 2. 刷新表格(重新加載數據) // 重新加載所有數據 // [self.tableView reloadData]; // deleteRowsAtIndexPaths讓表格控件動畫刪除指定的行 [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; ~~~ ### UITableView 增加 要實現守代理方法 tableView.delegate = self; ~~~ // 返回編輯樣式,如果沒有實現此方法,默認都是刪除 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { // if (indexPath.row % 2) { // return UITableViewCellEditingStyleInsert; // } else { // return UITableViewCellEditingStyleDelete; // } return UITableViewCellEditingStyleInsert; } ~~~ 下面是在- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 方法中設置的 判斷編輯樣式,是刪除還是增添,然后做相應操作 ~~~ if (editingStyle == UITableViewCellEditingStyleInsert) { NSLog(@"要添加數據"); // 1. 向數組添加數據 [self.dataList insertObject:@"旺旺旺旺狗狗" atIndex:indexPath.row + 1]; // 2. 刷新表格 // [self.tableView reloadData]; // insertRowsAtIndexPaths讓表格控件動畫在指定indexPath添加指定行 // 新建一個indexPath NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; [self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationMiddle]; ~~~ ### UITableView 移動 ~~~ // 只要實現此方法,就可以顯示拖動控件 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { // 界面數據UITableView已經完成了 // 調整數據即可 // [self.dataList exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row]; // 1. 將源從數組中取出 id source = self.dataList[sourceIndexPath.row]; // 2. 將源從數組中刪除 [self.dataList removeObjectAtIndex:sourceIndexPath.row]; NSLog(@"%@", self.dataList); // 3. 將源插入到數組中的目標位置 [self.dataList insertObject:source atIndex:destinationIndexPath.row]; NSLog(@"%@", self.dataList); } ~~~ ?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看