Two cells in one row in UITableView

无人久伴 提交于 2020-02-02 03:47:08

问题


I'm trying to build a grouped UITableView cell like the table in user details in Twitter's app (former Tweetie app).

It's a cell with two sides, and you can select any of them separately (and the background turns blue, like a rounded button).

Anyone did something like it or know how they made it?

A screen shot from the view (it's the following, tweets, followers and favorites cells)


回答1:


I was wanting to do the same in my own app, but I was also a bit clueless on how this was done in the Twitter app.

After having a long play with that cell in the Twitter app, trying to break it to see what it'd do (eg, pressing multiple buttons at the same time, scrolling while tapping etc XD), I think I've figured out how it's done.

From what I can see, it's a single UITableViewCell (ie spanning multiple lines) with a special custom contentView added into it that renders everything in there (text, lines etc). When a user taps the cell, the custom view works out which region of the overall cell was tapped (Possible by intercepting touchesBegan in the custom view class), and then redraws that particular region as highlighted (probably entirely within drawRect).

Since if you look VERY closely, the highligthed blue background overlaps the cell curved corner slightly (denoting it's being drawn over the top), my guess is the custom cell is also personally rendering the highlighted blue background (As opposed to the UITableViewCell doing it as per usually).

Hope that helped. It's not a very elegant solution, but it should hopefully do the trick.




回答2:


First off.... create a background image that is nothing but a white rectangle with a single grey line down the middle.

Next, subclass a UITableViewCell..... it has two custom style UIButtons. The background is the white image with the line down the middle from earlier.

assign clearColor to the button background image and button image.

Size and place buttons such that button1 and button 2 meet at the single grey line.

In your tableView where you plan to use this custom cell, make it a grouped style tableview.

Go crazy ^_^




回答3:


Use two UIButtons in your custom cell to make that.




回答4:


you can do anything you want in UITableViewCell class. then put it together inside the tableView and build and run men. the skies are the limits.



来源:https://stackoverflow.com/questions/3876646/two-cells-in-one-row-in-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!