开发者

Custom UITableViewCell image doesn't appear in the first row

I am facing this very weird problem, I have created a custom UITableViewCell on which I have a UIImageView on the left and on the right I have two UILabel.

When I run the program, I see all the image and the label appears on the table.

I have total of 5 rows that needs to be displayed

The only problem is the image starts displaying from the row 2 and goes upto row 6 where as the labels get displayed from row 1 to row 5.

Custom UITableViewCell .h file

@interface ProductViewCell : UITableViewCell {
 IBOutlet UILabel *titleLabel;
 IBOutlet UILabel *detailLabel;
 IBOutlet UIImageView *imageView;
}

@property (nonatomic, retain) UILabel *titleLabel; 
@property (nonatomic, retain) UILabel *detailLabel;
@property (nonatomic, retain) UIImageView *imageView;

And the UITableViewController that uses this is

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

    static NSString *CellIdentifier = @"Cell";

    ProductViewCell *cell = (ProductViewCell*)[tableView 
          dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

          NSArray *topLev开发者_JAVA百科elObjects = [[NSBundle mainBundle] 
                           loadNibNamed:@"ProductViewCell" owner:self options:nil];
  for(id currentObject in topLevelObjects){
   if([currentObject isKindOfClass:[UITableViewCell class]]){
    cell = (ProductViewCell *) currentObject;
    break;
     }
   }
   }

 NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

 cell.titleLabel.text = [dictionary objectForKey:@"name"];
 cell.detailLabel.text = @"";
 cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
           [NSURL URLWithString: [dictionary objectForKey:@"imageUrl"]]]]; 
 return cell;


}


I solved the problem by doing this in my tableViewController

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 120.0; //returns floating point which will be used for a cell row height at specified row index }


Perhaps it has something to do with the fact that imageView shadows the UITableViewCell definition. I think that row 6 would be displayed only if your tableView:numberOfRowsInSection: returns 6. It also might be something stupid, like the contents of the tableDataSource ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜