Create a chat interface and a chat interface
Layout of imitation QQ chat
Most of the materials found currently have such results, and the design ideas are the same,
A tableview uses a custom cell. After the cell is successfully created, it uses the data transmitted by an intermediary class to determine whether the data is sent on the left or right, and then re-draws the content or layout.
But xib is not good at code adaptation and layout.
First Interface
Then the custom cell
Although it looks strange, it is a simple and crude method based on the train of thought. In fact, this cell is actually merged when the two sides are separately displayed, through the data intermediary class, you can know that the data on the other side should be displayed, and then hide the data on the other side.
dataSource.blockConfigureCell=^(CellFour* cell,Message* model) { cell.CFMessage=model; switch (cell.CFMessage.MCellSystle) { case CellSystleLeft: { cell.headimageRight.hidden=YES; cell.CFbackGroundRight.hidden=YES; cell.message.text=model.MDictionary[@"message"]; } break; case CellSystleRight: { cell.headImage.hidden=YES; cell.CFbackGroundLeft.hidden=YES; cell.messageRight.text=model.MDictionary[@"message"]; } break; default: break; } };
In fact, this is also a very helpless practice. At the beginning, two custom cells were used, that is, the display cells on the left and right were opened independently, however, two reusable labels will be generated during registration. Even if they are not displayed, the above results can be achieved, however, once you enter the reuse queue, you will only use the latest modified reuse tag. The final result is that all styles become one style regardless of the left or right.
Then I tried again. A custom cell contains two styles. Although the problem of reuse of labels is solved, the problem is the problem of cell creation, this will determine whether the cell is displayed on the left or on the right after creation, but the intermediate class of the cell is passed to tell the cell
The cell has been created when the style is used (cell is empty if data is passed before creation ). It cannot achieve the goal of dynamic adjustment.
The problem is recorded for the moment, so if the two sides want to achieve different display effects, they will be like different bubbles of qq (xib will be more troublesome, but it will be simpler ).