天天看點

0819-TableView(tableVeiw控件的代理)(tableView單組 lol資料展示)(tableView-汽車品牌logo 右側a-z)(KVC)(tableView - 添加删除按鈕出現)(自定義代理delegate)(記憶體)

------------------

tableVeiw控件的代理(dataSource) 與delegate屬性類似 隻是名稱不一樣

self.dataSource = self;

設定tableView控件的dataSource 為viewController

設定tableView的樣式為 group / plain  (group有分組效果)

1、tableView上下左右 20 0 0 0加限制

2、節組數 行數 單元格 節組頭文字 節組底文字

Sections(tableView中的節組數 numberOfSectionsInTableView)、 Rows(節組中的行數 numberOfRowsInSection)、

cell(tableView的單元 cellForRowAtIndexPath) 、

titleForHeaderInSection  (節組頭部的文字)、titleForFooterInSection (節組底部的問題)

------------

tableView單組 lol資料展示

1、做Hero資料模型

2、heros資料懶加載

3、tableView懶加載 (建立tableView樣式為plain  設定代理datasource  )

4、實作sourceData代理協定方法

 5、指定tableView.delegate = self  設定每一行不同高度 (heightForRowAtIndexPath)

(方法2:不用delegate 那麼可以 tableView.rowHeight = 44//預設的 效率高 但是每一行隻能固定都是這麼多了)

 6、Cell右邊的箭頭設定

(

 1設定 tableView.delegate = self

 2cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 會觸發行的選中

cell.accessoryView不會觸發行的選中 

)

7、UITableView點選哪一行

1設定tableView.delegate = self

2didSelectRowAtIndexPath  (取消選中某一行didDeSelectRowAtIndexPath 很少用到 先點選第二行 再點選第三行  這時候執行了取消選中第2行)

 8、點選小箭頭執行的方法

accessoryButtonTappedForRowAtInDexPath;

9、點選accessoryButton類型控件等

accessoryButtonTappedForRowWithIndexPath; //隻能監聽accessoryButton類型控件  其他類型控件需要單獨添加監聽方法

10、tableView根據 可重複使用cell标記取出 取出cell   ,  如果沒有,那麼建立cell ,并cell自己設定可重用标記

11、設定cell的背景圖檔 無需指定view大小  backgroundView無需指定 自動根據圖檔大小來顯示

UIImage *bgImage = [UIImage imageNamed:@"img_01"];

cell.backgroundView = [[UIImageView alloc] initWithImage:bgImage];

12、tabelView設定分割線 分割線顔色

tableView.seperatorStyle = UITableViewCellSeperatorStyleSingleLine;

tableView.seperatorColoer = [UIColor redColor];

13、設定tableView最頂部和最底部View

self.tableView.tableHeaderView

self.tableView.tableFooterView

0819-TableView(tableVeiw控件的代理)(tableView單組 lol資料展示)(tableView-汽車品牌logo 右側a-z)(KVC)(tableView - 添加删除按鈕出現)(自定義代理delegate)(記憶體)
0819-TableView(tableVeiw控件的代理)(tableView單組 lol資料展示)(tableView-汽車品牌logo 右側a-z)(KVC)(tableView - 添加删除按鈕出現)(自定義代理delegate)(記憶體)

View Code

 ------------

tableView-汽車品牌logo 右側a-z

步驟:

1、導入Log分類檔案夾

2、重寫carGroup 和Car類的description方法   改變輸出格式 NSLog(@"%@",carGroup);

3、設定tableView.datasource 實作UIDataSourceDelegate協定方法

4、右側 節點索引清單 sectionIndexTitlesForTableView

5、使用KVC的方式 設定右側索引清單

周遊所有房間Lists

周遊所有人員Lists

-------

KVC

     // 如果取值的對象是一個數組,同樣傳回一個數組   數組中包含dictinary取值方法

return [self.carGroups valueForKeyPath:@"title"];

 // NSArray *arr = [self.carGroups valueForKeyPath:@"cars.name"] //數組數組中dictionary中所有 cars鍵下的name鍵對應的值

//        [self setValuesForKeysWithDictionary:dict];

  //      [self setValue:dict[@"title"] forKey:@"title"];

------

tableView - 添加删除按鈕出現

tableView代碼建立,并實作協定

1、實作向左滑動删除出現 commitStyleEditing

2、開啟删除模式  左側出現紅色删除紅圈圈(點選後等同于向左滑動删除出現動作) self.tableView.editting = YES;

3、删除模式下 左側出現添加按鈕紅圈圈

2 +按鈕出現需要實作方法  并設定delegate self.tableView.delegate = self;

tableVieweditingStyleForRowAtIndexPath

紅圈圈,綠圈圈

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

 //   if (indexPath.row % 2) {

  //      return UITableViewCellEditingStyleInsert;

//    } else {

  //      return UITableViewCellEditingStyleDelete;

  //  }

    return UITableViewCellEditingStyleInsert;

}

3、

commitEditingStyle 送出添加操作後執行

[self.dataList removeObjectAtIndex:indexPath.row];

[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];

[self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationMiddle];

代碼:

0819-TableView(tableVeiw控件的代理)(tableView單組 lol資料展示)(tableView-汽車品牌logo 右側a-z)(KVC)(tableView - 添加删除按鈕出現)(自定義代理delegate)(記憶體)
0819-TableView(tableVeiw控件的代理)(tableView單組 lol資料展示)(tableView-汽車品牌logo 右側a-z)(KVC)(tableView - 添加删除按鈕出現)(自定義代理delegate)(記憶體)

自定義代理delegate

寫 控制器<***delegate>遵守協定是為了友善敲代碼 有提示      遵守了協定就等同于寫了這個方法協定方法的聲明   需要寫出方法的實作部分  

1、定義appView的delegatez協定

@class HMAppInfo, HMAppView;

// 1. 協定名以類名開始+Delegate

@protocol HMAppViewDelegate <NSObject>

@optional

// 2. 協定方法,以類名開始(沒有類字首),第一個參數是自己

// 隻是定義方法名,不做具體實作

- (void)appViewDidClickDownloadButton:(HMAppView *)appView;

@end

// 3. 定義代理屬性,遵守了HMAppViewDelegate協定的任意一個對象,都可以成為代理

@property (nonatomic, weak) id<HMAppViewDelegate> delegate;

2、設定appView的代理為控制器  

appView.delegate = self;

3、判斷代理時候實作了該代理方法 self.delegate reponseToSelector:selector(appViewDidClickDownloadButton:)

/** appView - xib裡的按鈕 連線監聽方法 */

- (IBAction)click:(UIButton *)button

    if ([self.delegate respondsToSelector:@selector(appViewDidClickDownloadButton:)]) {

        // 2> 如果實作了,再通知代理去工作

        [self.delegate appViewDidClickDownloadButton:self];

    }

 ------

記憶體

IOS程式啟動

iphone手機應用程式 棧區占據1M記憶體空間     mac占據的是8M

其他不重要的

數組中取出的都是id類型的  隻能使用get方法  不能用 點. 文法

可變數組和不可變數組的使用

NSArray *array = @["1","2"];

_arrayList = [NSMutableArray arrayWithObjects:@"張1",@"張2",@"張3",@"張4",@"張5",@"張6",@"張7",@"張8",@"張9",@"張10",@"張11",@"張12", nil];

對象包裝成數組 @[obj]