当我在pyObjC代码中调用setDelegate_
时,我得到一个AttributeError: 'tuple' object has no attribute 'setDelegate_'
。在
我的代码如下:
def createMovie(self):
attribs = NSMutableDictionary.dictionary()
attribs['QTMovieFileNameAttribute'] = '<My Filename>'
movie = QTMovie.alloc().initWithAttributes_error_(attribs, objc.nil)
movie.setDelegate_(self)
编辑
我发现我不能对movie对象使用任何实例方法。在
从您的注释来看,
QTMovie.alloc().initWithAttributes_error_
实际上返回了一个双元素元组,其中第一个元素是您想要的对象,第二个元素中有其他对象(可能是错误?)在您应该能够访问该对象:
选择器“initWithA属性:错误:“在Objective-C中有两个参数,第二个参数是通过引用传递的输出参数。Python没有通过引用传递的参数,因此PyObjC将该值作为第二个返回值返回,这就是此选择器的Python包装器返回元组的原因。这是一种通用机制,也可用于其他具有传递引用参数的方法。在
在目标C中:
在Python中:
^{pr2}$相关问题 更多 >
编程相关推荐