iOS4.3でこのメソッドを使用するために、「dismissViewControllerAnimated:completion:」をオーバーライドしてきました。しかし、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)です
- 非常に短いサンプルコードを記述しましたが(単にモーダルビューを表示して閉じます)、同じエラーが発生しました。
この状況を解決する方法がわかりません...助けてください