我一直在重写“dismissViewControllerAnimated:completion:”以在iOS4.3中使用此方法。 但是,自从我更新Xcode(4.6.1)
以来,这种技术出现了运行时错误error: address doesn't contain a section that points to a section in a object file
神秘地说,“presentViewController:animated:completion:”方法正在使用没有问题......
这是我使用的“UIViewController + Compatibility.h”。
@implementation UIViewController (Compatibility)
- (void)iOS4_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
[self presentModalViewController:viewControllerToPresent animated:flag];
[self performSelector:@selector(callBlock:) withObject:completion afterDelay:(flag ? 0.5 : 0)];
}
- (void)iOS4_dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
[self dismissModalViewControllerAnimated:flag];
[self performSelector:@selector(callBlock:) withObject:completion afterDelay:(flag ? 0.5 : 0)];
}
- (void)callBlock:(void (^)(void))block
{
if (block) {
block();
}
}
+ (void)iOS4compatibilize
{
// presentViewController:animated:completion:
Method m1 = class_getInstanceMethod(self.class, @selector(iOS4_presentViewController:animated:completion:));
class_addMethod(self.class,
@selector(presentViewController:animated:completion:),
method_getImplementation(m1),
method_getTypeEncoding(m1));
// MEMO:
// This cause a bug.
// Method m2 = class_getClassMethod(self.class, @selector(iOS4_dismissViewControllerAnimated:completion:));
// Here is the answer.
// dismissViewControllerAnimated:completion:
Method m2 = class_getInstanceMethod(self.class, @selector(iOS4_dismissViewControllerAnimated:completion:));
class_addMethod(self.class,
@selector(dismissViewControllerAnimated:completion:),
method_getImplementation(m2),
method_getTypeEncoding(m2));
}
@end
有人有同样的问题吗?
备忘:我已经尝试过这些东西了。
我不知道要解决这种情况......请帮忙
答案 0 :(得分:0)
这是解决方案。 (我使用了错误的功能)
+ (void)iOS4compatibilize
{
// presentViewController:animated:completion:
Method m1 = class_getInstanceMethod(self.class, @selector(iOS4_presentViewController:animated:completion:));
class_addMethod(self.class,
@selector(presentViewController:animated:completion:),
method_getImplementation(m1),
method_getTypeEncoding(m1));
// dismissViewControllerAnimated:completion:
Method m2 = class_getInstanceMethod(self.class, @selector(iOS4_dismissViewControllerAnimated:completion:));
class_addMethod(self.class,
@selector(dismissViewControllerAnimated:completion:),
method_getImplementation(m2),
method_getTypeEncoding(m2));
}