无法访问导航控制器后退按钮

时间:2013-10-15 14:57:32

标签: ios objective-c uinavigationcontroller back-button

在我的应用程序的详细视图中,导航控制器的后退按钮似乎从一些不道德的表现中获取其颜色的提示。通过一条通向细节视图的路径,它是蓝色的;通过另一个,它是黑色的。在任何一种情况下,后退按钮似乎都不存在于self.navigationController对象中。

所以这是一个详细视图:

detail view of my app

此处是导航控制器的快照:

enter image description here

我很确定我知道如何更改此特定元素的颜色,但我不知道在哪里可以找到它。想法?

VenueTableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *show;

    if( [self.listType isEqualToString:@"showsByRegion"] )
    {
        NSString *venueIndex = [[self.allShows allKeys] objectAtIndex:[indexPath indexAtPosition:0]];
        int index = [indexPath indexAtPosition:1];
        show = [[self.allShows objectForKey:venueIndex] objectAtIndex:index];
    } else {
        int index = [indexPath indexAtPosition:(indexPath.length - 1)];
        show = [self.showsAtVenue objectAtIndex:index];
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                         bundle:[NSBundle mainBundle]];

    detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];

    detailViewController.showInfo = show;

    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];

}

InfoViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView = [[self.view subviews] objectAtIndex:1];

    [self createInfoViewDictionary];
    [self addTopImage];
    [self setFrameForTableView];
    [self bindLabelsToProperties];

    [self.navigationController.navigationBar setTitleTextAttributes:[SHColors sharedInstance].navBarText];
}

6 个答案:

答案 0 :(得分:3)

导航栏上的后退按钮属于后退按钮发送给您的视图控制器。 即。

A --->B --->C

C的后退按钮属于B导航项,B的后退按钮属于A导航项。

这意味着您需要检查在上一个View Controller中执行的操作。

答案 1 :(得分:3)

如果你得到不同的颜色是因为你从不同的viewcontrollers到达那里并且那些viewcontrollers有不同的tintColor。

然后,您需要使用以下颜色设置颜色:

- (void)viewDidLoad
{
    ....
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    ....
}

如果你想在所有导航栏中使用相同的颜色,你可以使用UIAppearance代理在AppDelegate中设置它们(编辑:正如Jordan Montel所说)

答案 2 :(得分:2)

如果您想更改整个标题颜色,可以在AppDelegate的方法tintColor中设置导航栏的didFinishLaunchingWithOptions

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];

didFinishLaunchingWithOptions方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
   [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    return YES;
}

答案 3 :(得分:1)

将导航控制器导航栏的tintColor设置为您想要后退按钮的颜色。

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

在iOS 6上,这会将整个栏设置为白色。

如果您设置导航栏的某些超级视图的色调颜色,那么如果未设置后退按钮将继承它。

答案 4 :(得分:0)

视图的tintColor属性设置后退按钮的不同颜色,如果没有设置,则从超级视图继承。您可以在app delegate:

中执行此操作,为整个应用设置色调颜色

window.tintColor = [UIColor purpleColor];

根据您的情况,您需要回溯并查看每个导航路径中各个颜色的来源,并设置导航栏的tintColor属性。

答案 5 :(得分:0)

像@micantox一样,后退按钮来自之前的视图控制器。因此,如果您想访问当前控制器可见的后退按钮,您必须访问呈现视图控制器,因此最好的方法是:

self.presentingViewController.navigationItem.backBarButtonItem
相关问题