简体   繁体   English

定制的uitableview聊天气泡

[英]customized uitableview with chat bubbles

I'm building a SMS like app, with chat bubbles. 我正在建立一个类似应用程序的短信,聊天气泡。 To do that I'm using a customized uitableview which gets data from an array and puts cells with pair indexPath on the right and with odd indexPath on the left 要做到这一点,我正在使用一个自定义的uitableview,它从数组中获取数据,并在右侧放置带有indexPath的单元格,在左边放置奇数indexPath

Everything works fine, but the only problem is that there can't be 2 cells one above the other in the same same position (left or right) and I need this as maybe a user can send 2 or more messages while the other one didn't send anything 一切正常,但唯一的问题是在同一位置(左或右)不能在另一个上方放置2个单元,而我需要这样做,因为用户可以发送2条或更多条消息,而另一条没有什么都不发

I'm thinking in a way of doing that but nothing comes up to my mind so do you suggest a way ? 我正在考虑这样做,但没有任何事情出现在我的脑海中,所以你建议一个方法?

You can't assume that the two users will alternate messages back and forth, so the even/odd check will have to be thrown out. 您不能假定两个用户会来回交替发送消息,因此必须扔掉偶数/奇数检查。

You mention you store the messages in an array. 您提到将消息存储在数组中。 Perhaps create another array of the same size, and when you add a message to the first array, you can add something to the second array that lets you know which user it is from. 也许创建另一个相同大小的数组,当您向第一个数组添加消息时,您可以向第二个数组添加一些内容,让您知道它来自哪个用户。 Then, when you create your cells, you can determine if it should be on the left or right using the second array, and fill the content of the bubble from the message array. 然后,当您创建单元格时,可以使用第二个数组确定它应该在左侧还是右侧,并填充消息数组中气泡的内容。

Could you just check if the message originated from the device I'm holding and put it on the left side? 您能否检查消息是否源自我所持设备并将其放在左侧?

If the data you are pulling from somehow identifies the user, you could easily check which user sent the message and position the cell based on that. 如果您从某种方式提取的数据识别用户,您可以轻松检查哪个用户发送了消息并根据该位置定位了单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM