# Flipped cell when overriding tableView cellForRow method

**URL:** <https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467>\
**Category:** Sendbird Chat UIKit\
**Tags:** ios, uikit, bug\
**Created:** [December 17, 2020, 1:29pm UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467 "2020-12-17T13:29:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramonpicoplay](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ramonpicoplay/32/731_2.png) [@ramonpicoplay](https://community.sendbird.com/u/ramonpicoplay)\
**Post date:** [December 17, 2020, 1:29pm UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467/1 "2020-12-17T13:29:56Z")

</div>

I have to implement a lot of different types of cells. For each cell, I’m passing the SBDBaseMessage to know in which **position** the respective cell will be presented.

I have a SBUChannelViewController subclass, in which I override **cellForRow** method like that:

```
 override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) { 
      (...)
      return MyCustomChatCell()
 }

```

Cell creation works perfectly, I’ve instantiated my **SBUBaseMessageCell** subclass and called the `configure(message: _, position: _, hideDateView: _, receiptState: _)` method. But here’s the glitch: my cells **flipped**. Crazy right?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/sendbird/original/1X/1db06dd7762e1f67f80795a9252bd35085182933.png)

For now I’m doing this workaround:  
`layer.setAffineTransform(.init(scaleX: 1, y: -1))`

But I think that’s an SDK bug.

---

<div class="post-metadata">

**Author:** ![ramonpicoplay](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ramonpicoplay/32/731_2.png) [@ramonpicoplay](https://community.sendbird.com/u/ramonpicoplay)\
**Post date:** [December 17, 2020, 1:51pm UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467/2 "2020-12-17T13:51:26Z")

</div>

Here’s my custom files, that you can check:  
[DMSBPaymentCardCell.swift](https://community.sendbird.com/uploads/short-url/wnRP5o7as7Zg8YlxoOEWZCuU1cN.swift) (4.5 KB)  
[DMSBChatViewController.swift](https://community.sendbird.com/uploads/short-url/dULoTH3qSSGFY4sUiU93YU0HQPS.swift) (5.8 KB)

---

<div class="post-metadata">

**Author:** ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)\
**Post date:** [December 17, 2020, 2:38pm UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467/3 "2020-12-17T14:38:18Z")

</div>

its not actually glitch but you have to transform up side down to display properly on channel view. The reason is because tableview itself is already up side down (its pretty normal on chat view). I think we need to clearly state this on documentation. Thanks for the feedback tho!

---

<div class="post-metadata">

**Author:** ![adrianodiasw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/adrianodiasw/32/757_2.png) [@adrianodiasw](https://community.sendbird.com/u/adrianodiasw)\
**Post date:** [December 17, 2020, 6:21pm UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467/4 "2020-12-17T18:21:05Z")

</div>

@Woo, could you elaborate the reason for the table view being upside down? It is not clear for us.

Also, for now, if you can share any material exploring the subject, it will be welcomed.

---

<div class="post-metadata">

**Author:** ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)\
**Post date:** [December 18, 2020, 5:08am UTC](https://community.sendbird.com/t/flipped-cell-when-overriding-tableview-cellforrow-method/1467/5 "2020-12-18T05:08:50Z")

</div>

The reason why tableview is up side down is because it is more convenient to insert latest message at the top rather than at the bottom of tableview. So when you scroll down (attempting to read previous message), we append newly fetched previous messages to the list so it naturally displays on the bottom of the tableview (though it seems on top of the view because its up side down). Thats one way to implement chat view. You can find more information on google (here one [https://blog.kulman.sk/filling-uitableview-from-bottom-top/](https://blog.kulman.sk/filling-uitableview-from-bottom-top/))
