Symbol not found: _OBJC_CLASS_$_UIPopoverController

亡梦爱人 提交于 2019-11-28 18:50:32

Even if they're not loaded in runtime, those files are still processed in linking. The symbol _OBJC_CLASS_$_UIPopoverController is therefore added into your app as one of those requiring dynamic linking.

There are 2 workarounds,

  1. Replace all appearance of UIPopoverController in a message (e.g. [UIPopoverController alloc]) with NSClassFromString(@"UIPopoverController"), or
  2. Make UIKit weakly linked.

I strongly recommend you not weakly link UIKit. As KennyTM and I mentioned in our comments, this may hide future linker issues and result in crashes. I'm also simply not comfortable with telling the linker that UIKit is optional when it plainly isn't. Big hack.

Instead, initialize and call UIPopoverController indirectly using NSClassFromString:

Class popover = NSClassFromString(@"UIPopoverController");
if (nil != popover)
{
    self.myPopover = [[popover alloc] initWithContentViewController:myContent];
}

If you still have linker errors, you may need to call UIPopoverController's messages using NSSelectorFromString:

Class popover = NSClassFromString(@"UIPopoverController");
if (nil != popover)
{
    SEL myInit = NSSelectorFromString(@"initWithContentViewController:");
    self.myPopover = [[popover alloc] performSelector:myInit withObject:myContent];
}

For portability, I recommend writing a proxy object to handle these implementation details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!