2012-07-29 55 views
0

我有我定制表视图,但是当我选择它,它只会选择半... 看:定制表视图亮点

without highlight

highlighted

无亮点:

突出显示:

我从控制tableview中的类代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 

    // create the parent view that will hold header Label 
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)]; 

    // create image object 
    UIImage *myImage = [UIImage imageNamed:@"trolley.png"];; 

    // create the label objects 
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
    headerLabel.backgroundColor = [UIColor clearColor]; 
    headerLabel.font = [UIFont boldSystemFontOfSize:15]; 
    headerLabel.frame = CGRectMake(70,22,200,20); 
    headerLabel.text = @"Object"; 
    headerLabel.textColor = [UIColor darkGrayColor]; 

    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
    detailLabel.backgroundColor = [UIColor clearColor]; 
    detailLabel.textColor = [UIColor redColor]; 
    detailLabel.text = @"Quantity"; 
    detailLabel.font = [UIFont systemFontOfSize:15]; 
    detailLabel.frame = CGRectMake(230,20,230,25); 

    // create the imageView with the image in it 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage]; 
    imageView.frame = CGRectMake(10,10,50,50); 

    [customView addSubview:imageView]; 
    [customView addSubview:headerLabel]; 
    [customView addSubview:detailLabel]; 

    return customView; 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [lista count]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    return 60; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 

    return cell; 
} 

我希望你能理解我!

回答

2

tableView:viewForHeaderInSection:

文档...此方法仅适用正确时 的tableView:heightForHeaderInSection:也可以实现。

因此,您定义了自定义标题视图,但表视图控制器不知道它是60点高。因此表格标题与第一个单元格重叠。

添加

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
    return 60.; 
} 

应该有所帮助。

+0

谢谢!你真的帮了我! – 2012-08-01 00:41:13