Whoo-boy...I am spamming the airwaves this past couple days. Here's another one...in my attempts to get the NavigationView to be a little less half-baked for my purposes, I need a way to know when the back button is pressed. So I thought I'd be clever and insert my own UIBarButtonItem in the navigation bar the navigation controller is using so I could provide a target/action for when it is activated...so I tested it with this:
def backButtonBarItemAction(_self, _cmd):
print "target called!"
BackButtonBarItemTarget = objc_util.create_objc_class("BackButtonBarItemTarget",
methods=[backButtonBarItemAction])
target = BackButtonBarItemTarget.new().autorelease()
v1 = ui.View()
v1.name = "view1"
v2 = ui.View()
v2.name = "view2"
n = ui.NavigationView(v1)
n.push_view(v2)
nc = n.objc_instance.navigationController()
vc = nc.bottomViewController()
ni = vc.navigationItem()
print "nav item:",ni
print "back item:",ni.backBarButtonItem()
UIBarButtonItem = objc_util.ObjCClass("UIBarButtonItem")
print "target:",target
backitem = UIBarButtonItem.alloc().initWithTitle_style_target_action_(
"TEST",0,target,"backButtonBarItemAction")
backitem.autorelease()
ni.backBarButtonItem = backitem
print "custom back item:",backitem
print "back item now:",ni.backBarButtonItem()
n.present()
print "nav item after present:",ni
The strange thing here is that nothing seems to be wrong...the code all works with no tracebacks or errors in objective-c-land. However, while the back item text does change to "TEST", indicating my custom item is there, pressing the back button doesn't trigger my target selector...anyone have any ideas? I'm guessing something in the NavigationView implementation is overriding my target/action.