Now I just want to say I don't think this is a bug in pythonista.
I have a much larger "app" I'm working on in pythonista but for the problem I'm having I created a basic example so it isn't very nice code.
With that out of the way here is my example.
import ui
import time
class source (object):
def __init__(self):
self.selectcb = None
def tableview_number_of_rows(self, tv, s):
return 1
def tableview_cell_for_row(self, tv, s, r):
cell = ui.TableViewCell()
cell.text_label.text = 'DoubleTap'
return cell
def tableview_did_select(self, tv, s, r):
self.selectcb()
time.sleep(1)
view = ui.TableView()
s = source()
nav = ui.NavigationView(view)
w,h = ui.get_screen_size()
v2 = ui.View(frame=(0,0,w,h))
@ui.in_background
def cb():
time.sleep(1)
nav.push_view(v2)
time.sleep(1)
s.selectcb = cb
view.data_source = s
view.delegate = s
nav.present()
My problem is when I double tab the row it calls the call back to add the view to the navigation controller. Not sure this the best way to do it. I have put the sleeps in as in the other script I'm working on I do some processing before I push the view on, so I am simulating that with sleeps.
So if I double tap on the row and wait like 5 seconds after the view is pushed it crashes pythonista.
Anyway I know what the error is as I have the fault handler and exception catching script on so it produces this.
Fatal Python error: Aborted
Thread 0x000000016e247000 (most recent call first):
Objective-C exception details:
UIViewControllerHierarchyInconsistency: A view can only be associated with at most one view controller at a time! View
I have left the stack trace out. Now so I can see the issue but I don't know how to get around this from occurring. It appears to only happen when I have decorated the function to push the view on the navigation view in a ui.in_background
Any thoughts are appreciated.