TableView图像加载问题。(表格Cell的完整代码)

时间:2011-04-12 09:04:11

标签: ios4

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

    dictionary = [QuestionMutableArray objectAtIndex:0];

    static NSString * CellIdentifier = @“BeginingCell”;

    BeginingCell * cell =(BeginingCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){

    NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"BeginingCell" owner:self options:nil ];
    
    for(id CurrentObject in topLevelObjects)
    {
        if ([CurrentObject isKindOfClass:[BeginingCell class]]) {
    
            cell=(BeginingCell *) CurrentObject;
            break;
        }
    }
    

    }

    //配置单元格。

    如果(indexPath.row == 0) {

    cell.SectionTitle.text=[dictionary objectForKey:@"question"];
    cell.Option1.text=[dictionary objectForKey:@"option1"];
    cell.Option2.text=[dictionary objectForKey:@"option2"];
    cell.Option3.text=[dictionary objectForKey:@"option3"];
    cell.Option4.text=[dictionary objectForKey:@"option4"];
    
    
    UIImage *imgDef=[UIImage imageNamed:@"man_kirstie_alley.jpg"];
    [cell.myImageView setImage:imgDef];
    
    
    
    
    [MyTestArray release];
    
    [cell.button1 setTitle:@"A." forState:UIControlStateNormal];
    [cell.button2 setTitle:@"B." forState:UIControlStateNormal];
    [cell.button3 setTitle:@"C." forState:UIControlStateNormal];
    [cell.button4 setTitle:@"D." forState:UIControlStateNormal];
    

    }

    返回单元格;

}

1 个答案:

答案 0 :(得分:0)

我认为你必须先创建一个单元格。您可以使用这样的默认单元格:

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

static NSString *CellIdentifier = @"Cell";

//---try to get a reusable cell---

UITableViewCell *cell = [tableView
    dequeueReusableCellWithIdentifier:CellIdentifier];

//---create new cell if no reusable cell is available---
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
             reuseIdentifier:CellIdentifier] autorelease];
}

//---You would set the image here---
UIImage *imgDef=[UIImage imageNamed:@"man_kirstie_alley.jpg"];
cell.image = imgDef;

return cell;
相关问题