blmacbeth
Oct 24, 2015 - 14:53
I know Pythonista already has this with the console module, but I think it is a decent look at how to work with other UIViewControllers. This is very raw and needs to be cleaned up… maybe I'll make it into a class. Any way, here is the code
# coding: utf-8
from objc_util import *
import ui
UIAlertController = ObjCClass('UIAlertController')
UIAlertAction = ObjCClass('UIAlertAction')
def ok_pressed(sender):
print 'OK pressed'
app = UIApplication.sharedApplication()
win = app.keyWindow()
rvc = win.rootViewController()
## this was all setup for thealert view
alert = UIAlertController.alertControllerWithTitle_message_preferredStyle_(ns('My Alert'), ns('My Message'), 1)
alert_action_block = ObjCBlock(ok_pressed, None, [c_void_p])
default_action = UIAlertAction.actionWithTitle_style_handler_(ns('OK'), 0, alert_action_block)
alert.addAction_(default_action)
rvc.presentViewController_animated_completion_(alert, True, None)
Let me know what you think,
B