UITableView

1.代理   緩存

UITableViewDelegate,UITableViewDataSource

2.實現代理ide

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;  //分區數,默認爲1
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [data count]; //行數
}

//當TableView繪製某一行的時候,會調用tableView:cellForRowAtIndexPath函數,NSIndexPath經過index.section和index.Row能夠獲取到當前行分區的下標和行下標
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellTableIndetifier=@"CellTableIdentifier";
    //在緩存裏面找cell,若是沒有則從新建立
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellTableIndetifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellTableIndetifier];
    }
   //系統自帶
   // cell.detailTextLabel
   //cell.imageView
    cell.textLabel.text=[data objectAtIndex:indexPath.row];
    return cell;
}
View Code

 3.自定義Cell,Nib中加載函數

    static NSString *indentity=@"CustomCell";
    CustomTableViewCell *cell=(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:indentity];
    if (cell==nil) {
        NSArray *boundle=[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
        cell= [boundle objectAtIndex:0];
    }
View Code
相關文章
相關標籤/搜索