我正在使用QTMovieView和,有时,我会收到以下日志并跟随一个未知的选择器异常。该程序具有供用户设置以显示和隐藏QTMovieView Controller 的选项。该程序链接到的SDK是10.7
“[[StdMovieUISliderCell slideType]:无法识别的选择器已发送到实例”
谢谢你的帮助
最佳答案
这看起来像是OS X Mountain Lion 10.8中引入的错误(编辑:也有关于OS X 10.7的报告,请参见下面的评论)。我猜想QTMovieView
将在下一个主要的OS X版本中弃用。最好的解决方案是移至AV Foundation(AVPlayer
和相应的AVPlayerLayer
类)。苹果有一些documentation about playing back assets using this framework。
也就是说,如果您无法更新到AV Foundation或无法关闭“自动版式”,则仍然可以通过在运行时将缺少的方法动态添加到StdMovieUISliderCell
类来解决此问题。确保添加Objective C运行时头文件并尽早添加方法(例如,应用程序委托(delegate)中的+ (void)load
)。出于App Store静态分析器拒绝原因的原因,还可以在类名中添加一些简单的编码,例如rot13。
// Make sure that we have the right headers.
#import <objc/runtime.h>
// The selectors should be recognized by class_addMethod().
@interface NSObject (SliderCellBugFix)
- (NSSliderType)sliderType;
- (NSInteger)numberOfTickMarks;
@end
// Add C implementations of missing methods that we’ll add
// to the StdMovieUISliderCell class later.
static NSSliderType SliderType(id self, SEL _cmd)
{
return NSLinearSlider;
}
static NSInteger NumberOfTickMarks(id self, SEL _cmd)
{
return 0;
}
// rot13, just to be extra safe.
static NSString *ResolveName(NSString *aName)
{
const char *_string = [aName cStringUsingEncoding:NSASCIIStringEncoding];
NSUInteger stringLength = [aName length];
char newString[stringLength+1];
NSUInteger x;
for(x = 0; x < stringLength; x++)
{
unsigned int aCharacter = _string[x];
if( 0x40 < aCharacter && aCharacter < 0x5B ) // A - Z
newString[x] = (((aCharacter - 0x41) + 0x0D) % 0x1A) + 0x41;
else if( 0x60 < aCharacter && aCharacter < 0x7B ) // a-z
newString[x] = (((aCharacter - 0x61) + 0x0D) % 0x1A) + 0x61;
else // Not an alpha character
newString[x] = aCharacter;
}
newString[x] = '\0';
return [NSString stringWithCString:newString encoding:NSASCIIStringEncoding];
}
// Add both methods if they aren’t already there. This should makes this
// code safe, even if Apple decides to implement the methods later on.
+ (void)load
{
Class MovieSliderCell = NSClassFromString(ResolveName(@"FgqZbivrHVFyvqrePryy"));
if (!class_getInstanceMethod(MovieSliderCell, @selector(sliderType)))
{
const char *types = [[NSString stringWithFormat:@"%s%s%s",
@encode(NSSliderType), @encode(id), @encode(SEL)] UTF8String];
class_addMethod(MovieSliderCell, @selector(sliderType),
(IMP)SliderType, types);
}
if (!class_getInstanceMethod(MovieSliderCell, @selector(numberOfTickMarks)))
{
const char *types = [[NSString stringWithFormat: @"%s%s%s",
@encode(NSInteger), @encode(id), @encode(SEL)] UTF8String];
class_addMethod(MovieSliderCell, @selector(numberOfTickMarks),
(IMP)NumberOfTickMarks, types);
}
}
在实现这两种方法时,我做了两个假设:
如果您的电影中有章节,则后者可能是个问题,但是我不知道该如何处理,因为我不需要或不使用它们。
关于cocoa - 有没有人见过 "[StdMovieUISliderCell sliderType]: unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10942006/