[Pyobjc-dev] Using delegates on iOS
Brought to you by:
ronaldoussoren
|
From: <end...@gm...> - 2011-07-08 21:54:27
|
Hi.
When I load UIKit with
myUIKit = objc.loadBundle("UIKit", globals(),
"/System/Library/Frameworks/UIKit.framework")
I import a lot of symbols, but a few protocols such as
UIImagePickerControllerDelegate and UINavigationControllerDelegate are not
loaded with this occasion (probably because they are not used in any any
other place).
Could you please tell me if you have an idea on what goes wrong when
using UIImagePickerController with UIImagePickerControllerDelegate in the
code below.
The symptom is the following: none of the methods of MyDelegate don't
get called, although ipc.takePicture() should call them.
Documentation on how to use UIImagePickerController at:
-
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html#//apple_ref/doc/uid/TP40010406
-
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/cl/UIImagePickerController
"""
Following
http://pyobjc.sourceforge.net/documentation/pyobjc-core/wrapping.html:
"If the framework defines any (informal) protocols you should add
objc.informal_protocol objects for those protocols to your module. These can
be defined in a submodule, as long as you arrange for that module to be
loaded whenever someone imports your package."
"""
UIImagePickerControllerDelegate =
objc.informal_protocol("UIImagePickerControllerDelegate", [
#- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
objc.selector(None,
selector="imagePickerController:didFinishPickingMediaWithInfo:",
signature="v@:@@"),
#- (void)imagePickerControllerDidCancel:(UIImagePickerController
*)picker
objc.selector(None, selector="imagePickerControllerDidCancel:",
signature="v@:@"),
#- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary
*)editingInfo
objc.selector(None,
selector="imagePickerController:didFinishPickingImage:editingInfo:",
signature="v@:@@@")
#objc.selector(None, selector="testMethod", signature="I@:",
isRequired=1), #isClassMethod=1
])
UINavigationControllerDelegate =
objc.formal_protocol("UINavigationControllerDelegate",
(objc.protocolNamed("NSObject"), ), [
#The protocol defines methods that the delegate CAN implement (NOT
mandatory)
#- (void)navigationController:(UINavigationController
*)navigationController didShowViewController:(UIViewController
*)viewController animated:(BOOL)animated
#- (void)navigationController:(UINavigationController
*)navigationController willShowViewController:(UIViewController
*)viewController animated:(BOOL)animated
])
#class MyDelegate(UINavigationControllerDelegate): #function takes at most 1
argument (3 given). ANYHOW BAD BECAUSE I MISTAKED AND USED
UINavigationControllerDelegate
class MyDelegate(NSObject, UIImagePickerControllerDelegate):
#- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
@objc.signature("v@:@@")
def imagePickerController_didFinishPickingMediaWithInfo_(self, picker,
info):
try:
print "Entered
imagePickerController_didFinishPickingMediaWithInfo_(self, picker = %s, info
= %s)." % (str(picker), str(info))
sys.stdout.flush()
picker.release()
except:
traceback.print_exc()
sys.stderr.flush()
#Provide 2.x compliance
#- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary
*)editingInfo
@objc.signature("v@:@@@")
def imagePickerController_didFinishPickingImage_editingInfo_(self,
picker, image, editingInfo):
try:
print "Entered
imagePickerController_didFinishPickingImage_editingInfo_(self, picker = %s,
image = %s, editingInfo = %s)." % (str(picker), str(image),
str(editingInfo))
sys.stdout.flush()
#NSDictionary *dict = [NSDictionary dictionaryWithObject:image
forKey:@"UIImagePickerControllerOriginalImage"];
self.imagePickerController_didFinishPickingMediaWithInfo_(picker, dict)
except:
traceback.print_exc()
sys.stderr.flush()
#- (void) imagePickerControllerDidCancel:
@objc.signature("v@:@")
def imagePickerControllerDidCancel_(self, picker):
try:
print "Entered imagePickerControllerDidCancel_(self, picker =
%s)." % (str(picker))
sys.stdout.flush()
self.dismissModalViewControllerAnimated_(objc.YES)
picker.release()
except:
traceback.print_exc()
sys.stderr.flush()
ipcDelegate = MyDelegate.alloc().init()
...
ipc = UIImagePickerController.alloc().init()
...
ipc.takePicture()
Thank you.
|