【问题标题】:How to set the cell background color for a TWTRTimelineViewController?如何为 TWTR 时间轴 ViewController 设置单元格背景颜色?
【发布时间】:2015-07-02 10:20:31
【问题描述】:

有谁知道如何为 TWTRTimelineViewController 设置单元格背景颜色?

我正在使用 Fabric 框架

cell.backgroundColor = UIColor.whiteColor() 等常用方法不起作用。

类参考可用here

【问题讨论】:

    标签: ios swift uitableview twitter-fabric


    【解决方案1】:

    很抱歉回复晚了,但希望它对您或某人有所帮助。 您必须在 TWTRTimelineViewController 中重写 willDisplayCell 委托方法,如下所示:

    对于swift 解决方案:

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if let cell = cell as? TWTRTweetTableViewCell {
            cell.backgroundColor = .clearColor()
            cell.tweetView.backgroundColor = .clearColor()
            // Do what you want with your 'tweetView' object
        }
    }
    

    对于Objective-c 解决方案:

    -(void)tableView:(UITableView *)tableView willDisplayCell:(TWTRTweetTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        cell.backgroundColor = [UIColor clearColor];
        cell.tweetView.backgroundColor = [UIColor clearColor];
        // Do what you want with your 'tweetView' object
    }
    

    记住TWTRTimelineViewControllerUITableViewController 的子类,这意味着您可以覆盖所有tableView 委托方法。

    请参阅 https://dev.twitter.com/twitter-kit/ios-reference/twtrtweettableviewcell 了解如何将 cell 作为 TWTRTweetTableViewCell 类实例。

    【讨论】:

    • 工作,但是,在运行时弄乱了 tableview 并导致奇怪的行为。
    【解决方案2】:

    使用下面的两个函数弄清楚了

    TWTRTweetView.appearance().backgroundColor = UIColor.whiteColor()
    TWTRTweetTableViewCell.appearance().backgroundColor = UIColor.whiteColor()
    

    【讨论】:

      【解决方案3】:
      // cell.backgroundColor = [UIColor blueColor];
      
       cell.contentView.backgroundColor = [UIColor blueColor];
      

      【讨论】:

      • 抱歉,我应该更详细一点,我使用的是 Fabric 框架,这意味着这不起作用
      【解决方案4】:

      在你的代码中写下以下几行:

      func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
      {
           cell.backgroundColor = UIColor.whiteColor()
      }
      

      【讨论】:

      • 抱歉,我应该更详细一点,我使用的是 Fabric 框架,这意味着这不起作用
      【解决方案5】:

      尝试:

      cell.tweetView.backgroundColor = UIColor.whiteColor()
      

      您可以在以下位置找到更多详细信息:https://dev.twitter.com/twitter-kit/ios/show-tweets

      【讨论】:

      • 抱歉,我应该更详细一点,我使用的是 Fabric 框架,这意味着这不起作用
      猜你喜欢
      • 2010-11-21
      • 2017-12-08
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 2019-07-27
      • 2022-07-18
      • 2012-06-06
      • 2019-10-21
      相关资源
      最近更新 更多