2012-07-29 47 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