无法识别的选择器 -[UIView addSubView:]

发布于 2024-11-14 14:12:09 字数 935 浏览 2 评论 0原文

我遇到了另一个与 iOS 相关的问题。这次涉及 UIView 上的 addSubView。

我将一堆 UIViewController 类存储在 NSMutableArray 中。这个想法是,根据用户从 UIPickerView 中选择的内容,它将把选择器视图移开,然后显示与视图控制器关联的视图。

为此,我有以下代码:

[navItem setTitle: [cheatArray objectAtIndex:row]];
UIViewController* controller    = [cheatViewControllers objectAtIndex: row];
if ( controller != nil )
{
    CGPoint animateTo;
    animateTo.x =  thePickerView.bounds.size.width  / 2;
    animateTo.y = -thePickerView.bounds.size.height / 2;
    [UIView animateWithDuration:0.5f delay: 0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{ [thePickerView setCenter: animateTo]; } completion:nil];

    [self.view addSubView: controller.view];
}

唯一的问题是,当我调用 addSubView 时,我收到错误:

 -[UIView addSubView:]: unrecognized selector sent to instance 0x581ba00

我不知道这是如何发生的。 addSubView 怎么可能是一个无法识别的选择器。当然它是内置的之一。有人对这里发生的事情有任何想法吗?

I'm having another iOS related issue. This time relating to addSubView on a UIView.

I am storing a bunch of UIViewController classes in an NSMutableArray. The idea is that depending on what the user picks from a UIPickerView it will move the picker view out the way and then display the view associated with the view controller.

To this end I have the following code:

[navItem setTitle: [cheatArray objectAtIndex:row]];
UIViewController* controller    = [cheatViewControllers objectAtIndex: row];
if ( controller != nil )
{
    CGPoint animateTo;
    animateTo.x =  thePickerView.bounds.size.width  / 2;
    animateTo.y = -thePickerView.bounds.size.height / 2;
    [UIView animateWithDuration:0.5f delay: 0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{ [thePickerView setCenter: animateTo]; } completion:nil];

    [self.view addSubView: controller.view];
}

The only problem is that when I call addSubView I get an error:

 -[UIView addSubView:]: unrecognized selector sent to instance 0x581ba00

I'm lost as to how this could happen. How can addSubView possibly be an unrecognised selector. Surely its one of the built in ones. Has anyone got any ideas as to what is going on here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我很OK 2024-11-21 14:12:09

尝试 addSubview (小“v”)

选择器区分大小写!

try addSubview (small "v")

Selectors are case-sensitive!

别在捏我脸啦 2024-11-21 14:12:09

应该是:

[self.view addSubview: controller.view];

Should be:

[self.view addSubview: controller.view];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文