我遇到了另一个与 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 怎么可能是一个无法识别的选择器。当然它是内置的之一。有没有人对这里发生的事情有任何想法?