0

viewForHeaderInSection:を使用してUINavigationTabBarにタイマーを追加しようとしました。しかし、それは時間を表示しません。 -(void)viewDidLoad メソッドで同じことを試してみると、動作しています。NavigationTabBar で NSDateFormatter を呼び出すことが可能かどうか、私のコードで何が間違っていますか? ここにコードがあります

- (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];
}
4

2 に答える 2

0

ビューを NavigationBar に追加するのを忘れました:

self.navigationItem.titleView = view;

したがって、コードは次のようになります。

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];
self.navigationItem.titleView = view;

そしてそれをViewDidLoadに入れます。;)

于 2013-04-02T10:30:44.867 に答える
0

viewDidLoad で設定してみてください:

 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];

それがうまくいくことを願っています。

于 2013-04-02T10:30:53.193 に答える