自定義tableviewcell(二)

//顯示view

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

    static NSString *CellTableIdentifier = @"CellTableIdentifier";
    static BOOL nibsregistered = NO;
    if(!nibsregistered)
    {
        UINib *nib = [UINib nibWithNibName:@"BIDNameAndColorCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifier];
        nibsregistered=YES;
    }
    BIDNameAndColorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    NSUInteger row = [indexPath row];
    NSDictionary *rowData = [self.computers objectAtIndex:row];
    cell.name = [rowData objectForKey:@"Name"]; cell.color = [rowData objectForKey:@"Color"];
    return cell;

}



//再storyboard中

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

{

    static NSString * identify=@"MealCell";

    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:identify];

    if(cell==nil)

    {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identify];

    }

    NSUInteger row = [indexPath row];

    UILabel *name=(UILabel *)[cell viewWithTag:1];

    UILabel *distance=(UILabel *)[cell viewWithTag:2];

    UILabel *detail=(UILabel *)[cell viewWithTag:3];

    UIImageView *imageview=(UIImageView *)[cell viewWithTag:4];

    name.text=[list_name objectAtIndex:row];

    distance.text=[list_distance objectAtIndex:row];

    detail.text=[list_detail objectAtIndex:row];

    UIImage *image=[UIImage imageNamed:@"qq.png"];

    imageview.image=image;

    return cell;

}


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