Tôi thêm một tableview vào một bộ điều khiển xem sau đó cố gắng thay đổi tiêu đề phần tiêu đề của nó trong IOS 6.0.Tiêu đề UITableViewForHeaderInSection không được gọi là
tôi sẽ được thay đổi chuỗi tiêu đề mỗi lần một chức năng cụ thể được gọi là như vậy Tôi không muốn để đối phó với (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Tôi cố gắng để sử dụng (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
nhưng khi tôi đặt một breakpoint tôi thấy rằng nó không được gọi.
tập tin in.h tôi thêm UITableViewDelegate, UITableViewDataSource
in.m
-(void)viewDidAppear:(BOOL)animated
{
//tableview init
self.meetingList=[[UITableView alloc] initWithFrame:CGRectMake(10, self.ckCal.frame.origin.y + self.ckCal.bounds.size.height+20, 384, 450) style:UITableViewStylePlain];
[self.meetingList setSeparatorStyle:UITableViewCellSeparatorStyleNone];
self.meetingList.delegate=self;
//populate mutablearray for tableview here
[self eventsInThisMonth:[NSDate date]];
[self.view addSubview:self.meetingList];
}
-(void)eventsInThisMonth:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM , yyyy"];
//self.firstSectionHeader=nil;
self.firstSectionHeader= [NSString stringWithFormat:@"Events in %@", [dateFormatter stringFromDate:date]];
NSLog(@" self.firstSectionHeader %@ ",self.firstSectionHeader);
}
#pragma Tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.eventHeaders count] + 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 35;
}
//set header section labels
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 35)] ;
[headerView setBackgroundColor:[UIColor colorWithRed:106/256.0 green:106/256.0 blue:106/256.0 alpha:1.0]];
UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 10, tableView.bounds.size.width, 20)];
subjectLabel.textColor = [UIColor whiteColor];
subjectLabel.font = [UIFont fontWithName:@"Gill Sans" size:20];
subjectLabel.backgroundColor = [UIColor clearColor];
subjectLabel.text=self.firstSectionHeader;
NSLog(@"subjectLabel.text %@",subjectLabel.text);
if (section==0) {
//[headerView addSubview:subjectLabel];
return headerView;
}
else
return nil;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section==0) {
NSLog(@"self.firstSectionHeader in titleForHeaderInSection %@",self.firstSectionHeader);
return self.firstSectionHeader;
}
else
return nil;
}
Tôi đang làm gì sai?
Nhìn vào mã của bạn ... Tại sao bạn muốn sử dụng cả hai, viewForHeaderInSection và titleForHeaderInSection? Bạn đang thiết lập tiêu đề trong viewForHeaderInSection anyway ... – Odrakir