iOS開發UI篇—UITableview控件使用小結

1、UITableview的使用ui

UITableViewDataSource   @requiredatom

1.多少組數據:spa

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;code

2.多少行數據orm

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;    繼承

3.設置cell的每組每行it

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
io

二、經過代碼方式自定義celltable

(1)新建⼀一個繼承自UITableViewCell的類class

(2)重寫initWithStyle:reuseIdentifier:方法

MessageCell.h

#import <UIKit/UIKit.h>
@interface MessageCell : UITableViewCell
@property (retain, nonatomic) UIImageView *headImageView;
@end

MessageCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor =  [UIColor colorWithHex:0xefefef];
        
        UIView *ticketKuang = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWith, cellHeight)];
        [self.contentView addSubview:ticketKuang];
        ticketKuang.backgroundColor = [UIColor whiteColor];
        
        //選擇按鈕
        selectBtn = [[UIButton alloc]initWithFrame:CGRectMake(-44, 5, 44, 44)];
        [selectBtn setImage:[UIImage imageNamed:@"icon_list_selectBox_normal"] forState:UIControlStateNormal];
        [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)]; //{top, left, bottom, right}
        [ticketKuang addSubview:selectBtn];
        
        return self;
    }
}
/****使用系統或者自定義cell*****/

//    static NSString *cellIdentify =@"cellIdentify";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
//    if(cell == nil)
//    {
          UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    }
相關文章
相關標籤/搜索