我試圖添加計時器到UINavigationTabBar使用viewForHeaderInSection:。 但它不顯示時間。如果我在 - (void)viewDidLoad方法中嘗試相同的工作。我的代碼有什麼問題,是否有可能在NavigationTabBar中調用NSDateFormatter?下面是代碼將NSDateFormatter設置爲HeaderSection
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
label1.backgroundColor=[UIColor blueColor];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"hh:mm:ss"];
label1.text=[dateFormatter stringFromDate:[NSDate date]];
[self performSelector:@selector(timeLimiteAlert) withObject:self afterDelay:1.0];
[view addSubview:label1];
[label1 release];
return [view autorelease];
}
ViewForHeaderInsection委託方法僅用於在tableviews中設置自定義節標題。請更好地解釋你想達到的目標。 –