0

我希望你能帮我设置控制器的背景颜色。

奇怪的是,当我在 Xcode 4.5.2 中构建代码时,它看起来如下图所示。如您所见,背景颜色消失了,它应该是(黄色)作为下一张图片 使用 Xcode 4.5.2 构建

当我在 Xcode 4.3.3 中构建代码时,它如下图所示。这就是它应该的样子。 使用 Xcode 4.3.3 构建

我的代码是这样的:

------------------InstantCabAppDelegate.m 文件-----------开始-------

//InstantCabAppDelegate.m file

orderController = [[OrderController2 alloc] initWithNibName:@"Order2" bundle:nil];
UINavigationController* firstnavigationController = [[UINavigationController alloc] initWithRootViewController:orderController];

------------------OrderController2.m 文件-----------开始-------

//OrderController2.m file

- (void)viewDidLoad 
{   
    [super viewDidLoad];

    [self.tableView setBackgroundColor:TABLE_VIEW_BACKGROUND_COLOR];
    [self.tableView setSeparatorColor:TABLE_VIEW_SEPARATOR_COLOR];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background-nologo"]];

    UIView *logoParentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 75)];
    UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_order_page"]];
    CGRect logoViewFrame = logoView.frame;
    logoViewFrame.origin.x = (self.view.frame.size.width / 2) - (logoViewFrame.size.width / 2);
    logoViewFrame.origin.y = 8;
    [logoView setFrame:logoViewFrame];
    [logoParentView addSubview:logoView];

    self.tableView.tableHeaderView = logoParentView;
    self.tableView.rowHeight = 50;

    [self.navigationController.navigationBar setTintColor:NAVIGATION_BAR_TINT_COLOR];

    [[MyLocation singleton] setDelegate:self];
    [self reset];

    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)];

    UIButton *orderButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [orderButton setFrame:CGRectMake(5, 0, footerView.frame.size.width - 10, 50)];

    [orderButton setBackgroundImage:[UIImage imageNamed:@"yellow_btn"] forState:UIControlStateNormal];
    [orderButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [orderButton setTitle:AMLocalizedString(@"kOrderOrderTaxiAlt", @"") forState:UIControlStateNormal];

    [[orderButton titleLabel] setFont:[UIFont boldSystemFontOfSize:orderButton.titleLabel.font.pointSize]];
    [orderButton addTarget:self action:@selector(checkOrder) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:orderButton];
    [self.tableView setTableFooterView:footerView];

    isShowingModalViewController = NO;
}
4

1 回答 1

0

I got this from Apple support:

UITableView applies a background view to itself when the table view's style is set to UITableViewStyleGrouped. The background view is used to draw the default pattern associated with that style table view but it also covers any custom background color that has been set. You can remove this background view by calling self.tableView.backgroundView = nil; from within viewDidLoad. Doing so will make your custom background color visible again.

? Apple Inc. | Apple Developer Technical Support

于 2012-12-11T09:22:56.727 回答