iPhone + UITableView +放置图像作为分隔符
我的应用程序中有 UITableView。
属性:TableStyle = Plain、SeperatorStyle = single 和 SeperatorColor = black
我想要做的是,我想放置一个图像(一个小条)作为表格的分隔符。
请帮我。
问候, 普拉蒂克
I have UITableView in my application.
Attributes: TableStyle = Plain, SeperatorStyle = single and SeperatorColor = black
What I want to do is that, I want to put a image (which a small strip), as separator for the table.
Please help me.
Regards,
Pratik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我有用的解决方案。
Solution which worked for me.
因此,通常对于 iPhone 表格,您应该只使用内置样式之一: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#// apple_ref/occ/instp/UITableView/separatorStyle
作为一直走这条路的 iPhone 开发人员,我建议您尽可能避免使用图像,并使用 API 来构建您的应用程序。
如果你坚持鲁莽的做法,或者如果你有客户要求这个或其他东西,那么你可以做的就是子类化 UITableViewCell。
在 UITableViewCell 子类中,您可以将所需的任何 UI 元素添加到单元格的 contentView 中,包括单元格底部的分隔符图像。
因此,这里是使用自定义 UITableViewCell 返回表格单元格的委托函数的实现:
然后这是我对 SavedTableCell.h 的简化实现:
这是一个简化的 SavedTableCell.m:
So, usually with an iPhone table, you should just use one of the built in styles: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/separatorStyle
As an iPhone developer who has been down this road, I suggest you avoid images wherever possible, and use the API to build your app.
If you insist on your reckless course, or if you have a client demanding this or something, then what you can do is subclass UITableViewCell.
In your UITableViewCell subclass, you can add whatever UI elements you want to the contentView of the cell, including a separator image at the bottom of the cell.
So, here is an implementation of the delegate function that returns a table cell using a custom UITableViewCell:
And then here's my simplified implementation of SavedTableCell.h:
And here is a simplified SavedTableCell.m:
我只想对安德鲁·约翰逊的回答添加一些想法。
如果您将子视图添加到 contentView 并使用 accesoryView 或图像,那么它将错误地显示分隔符图像。使用类似的东西
I want just to add some thoughts to Andrew Johnson's answer.
If you add subview to contentView and use accesoryView or image,then it'll show separator image incorrectly. Use something like