Search code examples
iosswifttwitterkit

Customizing table cells while using TWTRUserTimelineDataSource


I'm trying to load user timeline and customize cells, like replacing some text with emojis then display it. The sample code to load user timeline provided by twitter is like this:

override func viewDidLoad() {
    super.viewDidLoad()
    let client = TWTRAPIClient()
    self.dataSource = TWTRUserTimelineDataSource(screenName: "someuser", 
                      apiClient: client)
}

But I could not find any detail about customizing TWTRTweetTableViewCell while using data source method.


Solution

  • From the docs for TWTRTimelineViewController (link):

    This class is a UITableViewController subclass that displays TWTRTweetTableViewCell cells.

    That means you can override any UITableView delegate methods you wish.

    For example, to set the background color of the cell to Orange:

    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if let twCell = cell as? TWTRTweetTableViewCell {
            twCell.tweetView.backgroundColor = .orange
        }
    }
    

    It appears there are also "themes" you can configure. Just read through the docs... https://dev.twitter.com/twitterkit/ios/appledocs/Classes/TWTRTweetView.html