StoryBoard學習3 tableview實現

1、將tableview加入到其中一個ViewController中,設置tableview爲Grouped,設置成2個section,因爲2個section的數據不同,所以將 Prototype cells(模版cell)設置成2:(壓縮包中 1.jpg)


2、選擇其中一個cell,自定義我們的cell,並且加上Identifier,作爲第一個section的重用標飾符:(壓縮包中 2.jpg)


例外一個模版cell:(壓縮包中 3.jpg)



3、新建2個自定義的tableviewCell,與storyboard的cell象對應:(壓縮包中 4.jpg)


4、實現如下代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    

    if (indexPath.section == 0) {

        MessageSection0TableViewCell *cell = (MessageSection0TableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"message_section0"]; //直接通過標飾獲取cell

        cell.NotifiLb.text = notifArr[indexPath.row];

        return cell;

    }

    

    if (indexPath.section == 1) {

        MessageSection1TableViewCell *cell = (MessageSection1TableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"message_section1"];

        FriendObj *obj = friendsArr[indexPath.row];

        cell.NameLb.text = obj.f_name;

        cell.introLb.text = obj.f_intro;

        cell.HeaderIView.image = [UIImage imageNamed:@"icon_100"];

        return cell;

    }

    

    return nil;

}


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