在presentModalViewController中设置导航栏图像时出现问题

时间:2013-04-19 06:12:36

标签: ios navigationbar

这就是我在viewDidLoad中的第一个类中设置图像的方法,即tableView

  if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header.png"] forBarMetrics:UIBarMetricsDefault];
    }

now this how i go to detail view

 DetailViewController *dvController = [[DetailViewController alloc]   initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
      [self.navigationController pushViewController:dvController animated:YES];

在详细视图栏中,我为导航栏设置的图像自动出现,一切正常

现在我的问题是pushViewController工作正常,图像正在显示 但我在presentModelViewController中得到默认图像这就是我使用它的方式

- (void) modelappear
{

    if (self.testModalViewController == nil) 
    {
        TestModalViewController *temp = [[TestModalViewController alloc] initWithNibName:@"TestModalViewController" bundle:[NSBundle mainBundle]];
        self.testModalViewController = temp;
        [temp release];
    }

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.testModalViewController];
    [self presentModalViewController:nav animated:YES];
}

注意我只是在内部层次结构视图中设置按钮

你能告诉我我做错了什么吗?请给出解释和答案非常感谢

3 个答案:

答案 0 :(得分:0)

尝试这样,

     DetailViewController *dvController = [[DetailViewController alloc]   initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
     dvController.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIIMage imageNamed:@"name.png"]];
[self presentModalViewController:nav animated:YES];

答案 1 :(得分:0)

UIImage *image = [UIImage imageNamed:@"header.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    [self.navigationController.navigationBar addSubview:imageView];

答案 2 :(得分:0)

   UIImage *image = [UIImage imageNamed:@"header.png"];
    UIImageView *imageViewe = [[UIImageView alloc] initWithImage:image];


    UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 3, 150, 40)];
    [tmpTitleLabel setFont:[UIFont boldSystemFontOfSize:18]];


    tmpTitleLabel.text = @"Add Manually";

    tmpTitleLabel.backgroundColor = [UIColor clearColor];

    tmpTitleLabel.textColor = [UIColor whiteColor];

    CGRect applicationFrame = CGRectMake(0, 0, 300, 40);
    UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
    [newView addSubview:imageViewe];
    [newView addSubview:tmpTitleLabel];


    [self.navigationController.navigationBar addSubview:newView];