UITableView.appearance()。separatorStyle不工作

时间:2015-04-23 18:59:47

标签: uitableview swift uiappearance

在我的AppDelegate中,我设置了UITableView的外观,如background和rowHeight等。但不知何故,它对separatorStyle不起作用。有什么理由说它不起作用或者这是一个错误吗?使用separatorStyle在ViewController中设置tableView.separatorStyle = .None没有问题。

AppDelegate中的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    application.statusBarHidden = true

    UIToolbar.appearance().barTintColor = UIColor.grayColor()

    UITableView.appearance().backgroundColor = UIColor.blackColor()
    UITableView.appearance().rowHeight = 40
    UITableView.appearance().separatorStyle = .None

    UITableViewCell.appearance().backgroundColor = UIColor.clearColor()

    return true
}

奇怪的是,separatorColor确实有效。

编辑:

当我检查UITableView时,会显示:

// Appearance

var sectionIndexMinimumDisplayRowCount: Int // show special section index list on right when row count reaches this value. default is 0
@availability(iOS, introduced=6.0)
var sectionIndexColor: UIColor? // color used for text of the section index
@availability(iOS, introduced=7.0)
var sectionIndexBackgroundColor: UIColor? // the background color of the section index while not being touched
@availability(iOS, introduced=6.0)
var sectionIndexTrackingBackgroundColor: UIColor? // the background color of the section index while it is being touched

var separatorStyle: UITableViewCellSeparatorStyle // default is UITableViewCellSeparatorStyleSingleLine
var separatorColor: UIColor! // default is the standard separator gray
@availability(iOS, introduced=8.0)
@NSCopying var separatorEffect: UIVisualEffect? // effect to apply to table separators

有点奇怪,因为它在评论Appearance下面。与separatorColor相比,标题也没有任何不同。

1 个答案:

答案 0 :(得分:2)

没有什么"奇怪"或"不工作"或者"越野车"对这个。并非所有东西都是外观代理兼容的。看看标题:

@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
@property (nonatomic, retain) UIColor *separatorColor UI_APPEARANCE_SELECTOR; // default is the standard separator gray

注意什么? separatorColor已标记为UI_APPEARANCE_SELECTORseparatorStyle不是。这意味着您可以将separatorColor与外观代理一起使用,并且无法separatorStyle与外观代理一起使用。