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;
}
運行即可:
簡單列表 到此結束。