Objective c 包含在UITableView和UINavigationController中未按预期工作时的外观

Objective c 包含在UITableView和UINavigationController中未按预期工作时的外观,objective-c,ios7,uitableview,uinavigationcontroller,Objective C,Ios7,Uitableview,Uinavigationcontroller,我创建了一个简单的项目,其中有一个UINavigationController,右边有一个uibarbuttonite,还有一个UITableView。对于测试,我想使用AppearanceWhen contained in:将UINavigationController上的UIBarButtonItems涂成橙色,同时将UITableView中的UIButtons涂成红色。单独使用时,每个样式都能正确工作。但当我同时使用两者时,它就不起作用了。为什么 场景1(UINavigationContr

我创建了一个简单的项目,其中有一个UINavigationController,右边有一个uibarbuttonite,还有一个UITableView。对于测试,我想使用AppearanceWhen contained in:将UINavigationController上的UIBarButtonItems涂成橙色,同时将UITableView中的UIButtons涂成红色。单独使用时,每个样式都能正确工作。但当我同时使用两者时,它就不起作用了。为什么

场景1(UINavigationController中的彩色UIBarButtonItem):

[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];


场景2(UITableView中的彩色UIButton):

[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];


场景3(组合它们):

[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UIBarButtonItem 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];


可通过以下链接下载示例项目:

更新: 在我继续诊断问题的过程中,我发现如果我将UIButton的“setBackgroundColor”设置为红色而不是setTintColor,则UIButtonim将显示红色背景和橙色。由于某种原因,两种颜色都不起作用。。。仍然不确定原因。

这是有效的:

[[UIButton 
    appearanceWhenContainedIn:[UITableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UINavigationBar 
    appearanceWhenContainedIn:[UINavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];

当然,这可能会使一些你不想看到的东西变成橙色。

根据苹果的文档:

iOS 7不支持使用外观代理API设置tintColor属性

资料来源:

我将创建要引用的“empty”
UITableView
UINavigationController
子类,以避免意外更改其他按钮的外观

[[UIButton 
    appearanceWhenContainedIn:[MyTableView class], nil] 
        setTintColor:[UIColor redColor]];
[[UINavigationBar 
    appearanceWhenContainedIn:[MyNavigationController class], nil] 
        setTintColor:[UIColor orangeColor]];

这在iOS 7的测试期间是正确的,但现在已经不是这样了。他们收到了很多关于这方面的投诉,并对其进行了更改。:)这在哪里被记录下来了?它被现实记录下来了。:)
setTintColor:
确实适用于外观代理,OP的示例清楚地说明了这一点。以前,它不仅不起作用,甚至无法编译。我链接到的文档中没有提到您声称所做的更改。UIAppearance协议参考中也没有提到tintColor,如果您按照此处列出的说明获取符合协议的方法和属性列表,则tintColor不会显示:在某些情况下它工作的事实并不意味着它是受支持的行为。根据定义,如果它不在任何文档或公共标题中,则它是未记录的。谢谢,这确实符合我的要求。但你是对的,这会导致其他对象变成橙色,而这不是预期的。我很好奇是否还有办法解决这个问题。这个答案似乎是目前为止最好的。你必须单独处理这些其他对象,以防止它们变成橙色。-或者,嘿,你是手工制作这个工具栏按钮项目,为什么不在你这么做的时候把它的淡色设置成橙色呢?所以,在这个演示中我会这样做。但是对于我正在处理的当前项目,我正在使用类似的代码从代理中的一个位置更改应用程序的样式,在该位置我设置了所有颜色。这主要是因为我们的计划是在不重新设计轮子的情况下,为多种目的重新设计应用程序的外观。是的,我想。但我想说的是,这是一个错误,所以最底层的解决方案是手动设置单个条带按钮项目的色调。哦,请向苹果公司提交一个bug!您的示例非常有说服力,因为您可以证明它可以处理一个或另一个外观调用,但不能同时处理两个外观调用。