tableview 繪製cell

 

 

 //13繪製單元格的方法

 

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

{

 

    //14標識cell對象

 

 

 

    static NSString * cellindentfier=@"cell";

    //15查找是否可以重用得標識

 

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellindentfier];

 

 

 

    if (cell ==nil)

    {

 

        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellindentfier] autorelease];

 

 

 

    }

    //用來移出重複加載在cell上的view

 

    for(UIView*date in cell.contentView.subviews)

 

 

 

    {

 

        [date removeFromSuperview];

 

 

 

    }

 

    //cell加背景圖片

 

 

 

 

    cell.backgroundView=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell.png"]] autorelease];

 

 

 

 

    //電話

 

 

 

    

 

    UILabel *labe = [[UILabel alloc]initWithFrame:CGRectMake(11,33,200, 20)];

 

 

 

 

    labe.text=[NSString stringWithFormat:@"%@",[[array objectAtIndex:indexPath.row]valueForKey:@"third"]];

 

 

 

 

    labe.font=[UIFont systemFontOfSize:10];

 

 

 

 

    labe.backgroundColor=[UIColor clearColor];

 

 

 

 

    labe.textColor=[UIColor whiteColor];

 

 

 

    labe.tag=indexPath.row;

 

    [cell.contentView addSubview:labe];

 

 

 

    [labe release];

 

    //17顯示每一條cell上面得內容

 

 

 

 

    //公司名稱

 

 

 

 

    cell.textLabel.text = [[array objectAtIndex:indexPath.row]valueForKey:@"first"];

 

 

 

 

    cell.textLabel.font=[UIFont systemFontOfSize:12];

 

 

 

 

    cell.textLabel.textColor=[UIColor whiteColor];

 

 

 

 

    //公司地址

 

 

 

 

    cell.detailTextLabel.text= [[array objectAtIndex:indexPath.row]valueForKey:@"second"];

 

 

 

 

    cell.detailTextLabel.font=[UIFont systemFontOfSize:10];

 

 

 

 

    cell.detailTextLabel.numberOfLines = 1;

 

 

 

    

 

    //18cell選擇時得樣式

 

 

 

 

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

 

 

 

    //19被選中時顏色得變化 默認藍色

 

    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

 

 

 

    return cell;


}

 
=======================================
=======================================
=======================================
=======================================
======================================

//13繪製單元格

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

{

    //14標識cell對象

    static NSString * cellindentfier=@"cell";

    //15查找是否可以重用得標識

   UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellindentfier];

    if (cell ==nil)

    {

        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellindentfier] autorelease];

    }

    //用來移出重複加載在cell上的view

    for(UIView*date in cell.contentView.subviews)

    {

        [date removeFromSuperview];

    }

    //cell加背景圖片

    cell.backgroundView=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cellBigOpcaty.png"]] autorelease];

   

    

    //加論壇標題

    UILabel * labe = [[UILabel alloc]initWithFrame:CGRectMake(130,25,200, 20)];

    labe.text=[NSString stringWithFormat:@"%@",[[array objectAtIndex:indexPath.row]valueForKey:@"title"]];

    labe.font=[UIFont systemFontOfSize:14];

    labe.backgroundColor=[UIColor clearColor];

    labe.textColor=[UIColor whiteColor];

    [cell.contentView addSubview:labe];

    [labe release];

    //加圖片

    NSString * str = [[array objectAtIndex:indexPath.row]valueForKey:@"pic"];

    NSURL * url_josna=[NSURL URLWithString:str];

    NSURLRequest * request =[NSURLRequest requestWithURL:url_josna cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0f];

    //發送同步請求得到的數據

    NSData * data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    UIImage * image = [UIImage imageWithData:data];

    UIImageView * imageview =[[UIImageView alloc]initWithImage:image];

    imageview.frame=CGRectMake(10, 0, 100, 65 );

    [cell.contentView addSubview:imageview];

    //加右側小箭頭

    UIImageView *imageview2 =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"forumAccess.png"]];

    imageview2.frame=CGRectMake(285, 30, 20, 15);

    [cell.contentView addSubview:imageview2];

    

    [imageview release];

    //18cell選擇時得樣式

    cell.accessoryType=UITableViewCellAccessoryNone;

    //19被選中時顏色得變化 默認藍色

    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    return cell;

    

}

//cell寬度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 73;

}

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