IOS的delegate 設計模式,用法及利於其編寫列表 UITableView(具體編寫)

delegate 設計模式,用法及利於其編寫列表 UITableView(具體編寫)

在這裏插入圖片描述

在app中必須用到的設計模式,也是最常用的

在這裏插入圖片描述
UITanView 視圖 展示,協助管理,不管數據。
在這裏插入圖片描述
簡單列表編寫


    self.view.backgroundColor = [UIColor grayColor];
    UITableView *uiTabView = [[UITableView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:uiTabView];

在這裏插入圖片描述
引入datasurces
@interface ViewController ()``
在這裏插入圖片描述
實現tabview的兩個方法

//cell的數量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
//cell的樣式 佈局  數據
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *uiTabCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"name"];
    uiTabCell.detailTextLabel.text = @"副標題";
    uiTabCell.textLabel.text =  @"主標題";
    uiTabCell.imageView. image = [UIImage imageNamed:@"tab_purchasing_selector.png"];
    return uiTabCell;
}

在這裏插入圖片描述

在這裏插入圖片描述
運行即可:
在這裏插入圖片描述
簡單列表 到此結束。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章