TableView基本使用

TableView基本使用

基本步奏java

  • 1設置數據源
self.tableview.dataSource = self;
  • 2遵照協議
@interface ViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
  • 3實現方法
    有幾組
    每組有幾行
    每行設置什麼 內置了那些控件,本身點擊command查找

/**
* 不是必須實現的方法
*
* @param tableView
*
* @return tabeleview多少分組
*/
「`objc
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}ruby

/** * 必須實現的方法 * *  @param tableView *  @param section * *  @return 告訴tableview每一個分組有多少行 */
 ```objc
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }
    else if (section == 1)
    {
        return 3;
    }
    else
    {
        return 4;
    }
}

/**
* 對分組每行的內容進行設置
*
* @param tableView
* @param indexPath
*
* @return (UITableViewCell *)
*/markdown

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];

    if (indexPath.row == 0) {
        cell.textLabel.text = @"通用";
    }
    else if(indexPath.row == 1)
    {
        cell.textLabel.text = @"隱私";
    }
    else if (indexPath.row == 2)
    {
        cell.textLabel.text = @"必須";
    }
    else
    {
        cell.textLabel.text = @"得更新";
    }

    return cell;
}

效果圖:
運行效果ui

出現的問題圖:
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述atom

相關文章
相關標籤/搜索