UITableViewHeaderFooterView
クラスの使用に問題があります。私のアプリでは、プロパティの両方を使用してテキストを表示したいのですがtextLabel
、detailTextLabel
表示detailTextLabel
されません。私がAppleのドキュメントを理解している限り、textLabel
プロパティはよく知られているクラスのプロパティdetailTextLabel
と同様に機能するはずです。これが私のサンプルクラスコードです:textLabel
detailTextLabel
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
このコードをコンパイルすると、3つのセクションと各セクションに1つの行があるテーブルが表示されます。左側に「t」、右側に「dtext」のセクションがあると思いましたが、「dtext」がありません。私のコードのエラーはどこにありますか?detailTextLabelを表示するにはどうすればよいですか?プロパティの実用的な例へのリンクUITableViewHeaderFooterView
detailTextLabel
もいただければ幸いです。ありがとう!