@phuket2 I mentioned that I had seen something like this before... And I remember now that I had attempted to do it a long while back. Maybe a year ago when I was first learning some UI things. But I didn't know what I was doing. Some stuff sort of worked, but I ran into problems because I was trying to stick a webview in the tableviewcell. It wasn't working nice and I just thought it wasn't ever going to work.
I've learned a few things since. Now I've attempted to do again what I did before. The fix is really this little objc bit that gives the webview an opaque background - that way the selections in the tableview still work.
If there is a difference here from what @jonb is doing, I don't know what it is. I'm limited with my knowledge of how classes work (in the deep bowels of classes) so I don't know what's going on.
Anyway, try this out....
import ui
from objc_util import *
class MyTableViewDataSource (object):
def __init__(self, data):
self.data = data
def tableview_number_of_sections(self, tableview):
return 1
def tableview_number_of_rows(self, tableview, section):
return len(self.data)
def tableview_cell_for_row(self, tableview, section, row):
cell = ui.TableViewCell()
wv = ui.WebView(frame=cell.content_view.bounds, flex='WH')
wv.touch_enabled = False #necessary for tableview scrolling to work, unfortunate side effect is that you can't do any touch of content in the webview. Tried disabling scolling with objc but the result wasn't good either.
wv.scales_page_to_fit = False
wv.load_html(html)
#webview needs to have an opaque background for selection colors to work... do in objc
wv_obj = ObjCInstance(wv)
wv_obj.webView().setBackgroundColor_(ObjCClass('UIColor').clearColor())
wv_obj.webView().setOpaque_(False)
cell.content_view.add_subview(wv)
return cell
def tableview_can_delete(self, tableview, section, row):
return False
def tableview_can_move(self, tableview, section, row):
return False
def tableview_did_select(self, tableview, section, row):
t.name = self.data[row]['name']
if __name__ == '__main__':
from faker import Faker
fake = Faker()
style = '<style>p {font: arial 10pt; color:#888888; margin:0px} a {color:#888888; text-decoration:none} h4 {margin:0px; background-color:#dd7575; color:white; border-radius:5px; padding: 0 5}</style>'
contact_list = []
for x in range(200):
name, email, phone, address = fake.name(), fake.email(), fake.phone_number(), fake.address()
html = style + '<h4 style="margin:0px">{}</h4><p>{}</p><p>{}</p><p>{}</p>'.format(name, email, phone, address)
contact_list.append({'html':html, 'name':name})
t=ui.TableView()
t.frame=(0,0,400,480)
t.data_source=MyTableViewDataSource(contact_list)
t.delegate = t.data_source
t.row_height = 100
t.present('sheet')