0

我一直在覆盖“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

有人有同样的问题吗?

备忘录:我已经尝试过这些东西。

  • 清理我预先编译的二进制文件。
  • 重新启动 Xcode,或重新启动我的 Mac。
  • 我的 Xcode 是当前最新版本(4.6.1 版)
  • 我写了很短的示例代码(它只是显示模态视图,然后关闭),但我得到了同样的错误。

我不知道如何解决这种情况...请帮助

4

1 回答 1

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));
}
于 2013-03-22T01:47:08.507 回答