我有一個uitabbarcontroller,它有一個UIViewController添加到它。 (我儘量減少到最小的情況)。這個視圖控制器調用一個UIView,它通過以下方式繪製一個UIButton:UITabbarController沒有正確繪製視圖
- (void)drawRect:(CGRect)rect
{
CGRect brect = CGRectMake(0, 330, 60, 27);
CGPoint centern=CGPointMake(CGRectGetMidX(brect), CGRectGetMidY(brect));
UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:brect];
[button setCenter:centern];
[button setTitle:@"New" forState:UIControlStateNormal];
[self addSubview:button];
}
該按鈕繪製時沒有內部文本。只有當我觸摸顯示屏時,它才能正確繪製。
我的解決方案如下:給Tab Bar控制器兩個UIViewControllers來控制。然後迫使第二種的平局,然後再回到第一個:
tabBarController.selectedViewController = [tabBarController.viewControllers objectAtIndex:1];
tabBarController.selectedViewController = [tabBarController.viewControllers objectAtIndex:0];
此解決方案,但它是一個愚蠢的黑客。有一個更好的方法嗎?
UIView上的哪個方法用於初始化和添加按鈕? – 2010-07-02 13:52:43