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

时间:2011-06-10 11:05:25

标签: iphone objective-c ios uiview addsubview

我有另一个iOS相关问题。这次与UIView上的addSubView有关。

我在NSMutableArray中存储了一堆UIViewController类。我们的想法是,根据用户从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怎么可能是一个无法识别的选择器。肯定是其中一个内置的。有没有人对这里发生的事情有任何想法?

2 个答案:

答案 0 :(得分:8)

尝试addSubview(小“v”)
选择器区分大小写!

答案 1 :(得分:4)

应该是:

[self.view addSubview: controller.view];