Forum Archive

Can't make TableView work in the xcode template. ui Bug?

zencuke

The code in the following gist works fine as a script In Pythonista. When I copy it into Script.py is a python template it will build and run and display the TableView and then fail (with an exception) later.

https://gist.github.com/zencuke/9fd9ef0ee97af56301cb

To make it fail enter a number into the TextField and press save. The data should show up in the TableView. Do it again. The second time fails for me. There are different paths through the code that get the same failure. What they all have in common is updating the TableView. The exception thrown follows:

PythonistaProject`-[SUITableView tableView:didEndDisplayingCell:forRowAtIndexPath:] at simpleuimodule.m:

2014-10-30 03:35:14.283 PythonistaProject[523:61887] +[UIResponder omfirstResponder]: unrecognized selector sent to class 0x33448ea0 2014-10-30 03:35:14.286 PythonistaProject[523:61887] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIResponder omfirstResponder]: unrecognized selector sent to class 0x33448ea0' 

This is a substantially simplified version of the original app. I would be happy to simplify it more if that would help debug. Note: Turning on exception breakpoints before running gives a more meaningful stack trace (thanks jonB.) I'm running the latest xcode on the latest osx yosemite.

Thanks

-steve (aka zencuke)

JonB

Ok, again, I don't have xcode, but I see a few possible issues:

1). Is it valid to call

  pickle.dump(data,open(self.file,'wb'))

without closing the file? I know that

  with open(self.file,'wb') as file:
             pickle.dump(data,file)

will close it, but does the original guarantee immediate closing of the file handle, or only when GC is run? I don't know the answer, but if you try to open an already open file, maybe bad things happen.

2) try wrapping all of your callbacks like save() in @ui.in_background. Or, at a minimum the file writing. Not sure if you are seeing the errors in the simulator or on the device, but I could see file operations as being something you need to take off of the ui thread.

3) try adding a short ui.delay between your file write and table reload, and or rearrange the order. So possible options are

self.saveData
ui.delay(self.table.reload, 0.25)

Or

self.table.reload()
ui.delay(self.saveData, 0.25 )

This is pure speculation... , but adding ui.delays tends to fix lots of other ui locking issues in the app. Basically if the ui is animating, and your code is doing something else, things lock up, so the solution is to delay your code until the ui finishes animating. Perhaps what would be a lockup in the app turns into an exception in xcode, and for whatever reason the xcode timing is a little different such that this becomes an issue.

JonB

One other thought ... If the above don't work...

Try stubbing out all of the file operations.
Also maybe remove the end_editing... Just a hunch but that kicks off some ui animation, lowering the keyboard frame, then you ask the table to reload at the same time. Iirc I've had problems trying to do things to the ui while the kb frame is still animating. ui.delay should work for that problem too.

zencuke

Issue resolved. See "Debugging standalone" thread.