def main():
# ...
obj = waitForObject({"type": "UITableView", "visible": 1})
# Several call variants:
scroll_uitableview(obj, 0, 0)
scroll_uitableview(obj, 0, 1)
scroll_uitableview(obj, 0, 1, UITableViewScrollPositionBottom)
scroll_uitableview(obj, 0, 1, UITableViewScrollPositionBottom, True)
scroll_uitableview(obj, 0, 1, animated=True)
# Trying to scroll to non existing row;
# results in runtime error when table section contains
# only two rows:
# Fatal: Invalid row index for section 0: 2 (last row index of section 0: 1)
scroll_uitableview(o, 2, 0)
UITableViewScrollPositionNone = 0
UITableViewScrollPositionTop = 1
UITableViewScrollPositionMiddle = 2
UITableViewScrollPositionBottom = 3
def scroll_uitableview(uitableview_obj, section_index, row_index, uitableview_scroll_position=UITableViewScrollPositionMiddle, animated=False):
datasource = uitableview_obj.dataSource
last_section_index = datasource.numberOfSectionsInTableView_(uitableview_obj) - 1
if last_section_index < section_index:
test.fatal("Invalid section index: %s (last section index: %s)" % (section_index, last_section_index))
return
section_last_row_index = datasource.tableView_numberOfRowsInSection_(uitableview_obj, section_index) - 1
if section_last_row_index < row_index:
test.fatal("Invalid row index for section %s: %s (last row index of section %s: %s)" % (section_index, row_index, section_index, section_last_row_index))
return
index_path = NSIndexPath.indexPathForRow_inSection_(row_index, section_index)
uitableview_obj.scrollToRowAtIndexPath_atScrollPosition_animated_(index_path, uitableview_scroll_position, animated)