TableView Image Load Problem.(Full Code fot the tableCell)
(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 *开发者_StackOverflow) CurrentObject; break; } }
}
// Configure the cell.
if(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];
}
return cell;
}
I think you must create a cell first. You could use a default cell like this:
- (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;
精彩评论