不显示UITableViewHeaderFooterView.detailTextLabel

ale*_*ker 2 objective-c uitableview ios6

我的UITableViewHeaderFooterView课程用法有问题.在我的应用程序中,我想使用textLabeldetailTextLabel属性来显示一些文本,但detailTextLabel不显示.据我所知,Apple的文档textLabeldetailTextLabel属性应该类似于众所周知的类textLabeldetailTextLabel属性UITableViewCell.这是我的示例类代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tblMain;

@end

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize tblMain;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    tblMain.delegate = self;
    tblMain.dataSource = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *reuseIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    cell.textLabel.text = @"cell is not interesting";
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}// Default is 1 if not implemented


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *reuseIdentifier = @"header";
    UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
    if (!header) {
        header = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:reuseIdentifier];
    }
    header.textLabel.text = @"t";
    header.detailTextLabel.text = @"dtext";
    return header;
}

@end
Run Code Online (Sandbox Code Playgroud)

如果编译此代码,它将显示一个包含三个部分的表,每个部分中有一行.我以为我会在左侧获得带"t"的部分,在右侧获得"dtext"部分,但是"dtext"会被遗漏.我的代码中的错误在哪里?查看detailTextLabel要做什么?UITableViewHeaderFooterView detailTextLabel还将赞赏到财产工作示例的链接.谢谢!

小智 5

如果你查看标题UITableViewHeaderFooterView,你会发现detailTextLabel它只适用于UITableViewStyleGrouped.我猜你正在使用UITableViewStylePlain.

来自UITableViewHeaderFooterView.h:

@property(nonatomic, readonly, retain) UILabel* detailTextLabel; // only supported for headers in grouped style
Run Code Online (Sandbox Code Playgroud)