gpt4 book ai didi

objective-c - UITableViewHeaderFooterView.detailTextLabel 不显示

转载 作者:行者123 更新时间:2023-12-04 02:49:18 25 4
gpt4 key购买 nike

我遇到了 UITableViewHeaderFooterView 的问题类用法。在我的应用程序中,我想同时使用 textLabeldetailTextLabel属性显示一些文本,但是 detailTextLabel不显示。据我了解 Apple 的文档,textLabeldetailTextLabel属性应该类似于众所周知的 textLabeldetailTextLabel UITableViewCell 的属性类(class)。这是我的示例类代码:

#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

如果编译此代码,它将显示一个包含三个部分且每个部分一行的表格。我以为我会得到左侧为“t”、右侧为“dtext”的部分,但遗漏了“dtext”。我的代码哪里出错了?查看detailTextLabel需要做什么? UITableViewHeaderFooterView 工作示例的链接detailTextLabel属性(property)也将不胜感激。谢谢!

最佳答案

如果您查看 UITableViewHeaderFooterView 的 header ,您会发现 detailTextLabel 仅适用于 UITableViewStyleGrouped。我猜您正在使用 UITableViewStylePlain

来自UITableViewHeaderFooterView.h:

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

关于objective-c - UITableViewHeaderFooterView.detailTextLabel 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14380082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com