Aggiungo una vista tabella a un controller di visualizzazione, quindi provo a modificare i titoli delle intestazioni di sezione in IOS 6.0.UITableView titleForHeaderInSection non viene chiamato
Sarò cambiando le stringhe di intestazione ogni volta una funzione specifica viene chiamata così io non voglio affrontare (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Ho provato ad usare (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
ma quando ho messo un punto di interruzione vedo che il suo non essere chiamato.
lima in.h aggiungo 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;
}
Che cosa sto facendo di sbagliato?
Guardando il tuo codice ... Perché dovresti usare entrambi, viewForHeaderInSection e titleForHeaderInSection? Stai impostando il titolo in viewForHeaderInSection comunque ... – Odrakir