0

我有两个视图控制器,在第一个视图控制器中我有一个按钮,现在我想让用户点击该按钮,然后他们将转到第二个视图控制器。我没有使用情节提要并使用 ARC,我已经尝试过了,但它显示错误“uiviewcontroller 没有可见的@interface 声明选择器分配”。

- (IBAction)SendMsg:(id)sender {

    UIViewController *MessageViewController = [MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:MessageViewController animated:YES];
    [MessageViewController release];

}
4

4 回答 4

3

您将“*MessageViewController”声明为 UIViewController 类型。然后调用“MessageViewController”alloc 方法。你不能那样做。Maulik 是在正确的轨道上,但如果您使用 ARC,则需要删除最后一行([aMessageViewController release];)

尝试:

- (IBAction)SendMsg:(id)sender{
    MessageViewController *myMessageViewControllerInstance = [[MessageViewController alloc]  initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:myMessageViewControllerInstance animated:YES];
}

不要忘记,您需要一种方法来关闭模态视图控制器,并且您可以通过在上面的最后一行之前添加类似这样的内容来设置演示和过渡样式:

myMessageViewControllerInstance.modalPresentationStyle = UIModalPresentationFormSheet;
myMessageViewControllerInstance.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

还有其他样式,我只是用了例子。祝你好运

于 2012-10-10T13:39:37.683 回答
0
- (IBAction)SendMsg:(id)sender {

    MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
    [self presentModalViewController:aMessageViewController animated:YES];
    //[aMessageViewController release]; As you are using ARC

}
于 2012-10-10T13:31:55.870 回答
0
    - (IBAction)SendMsg:(id)sender {
        MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
        [self presentModalViewController:aMessageViewController animated:YES];
    }
于 2012-10-10T13:38:30.713 回答
0
    - (IBAction)SendMsg:(id)sender {

MessageViewController *aMessageViewController = [[MessageViewController alloc] initWithNibName:@"MessageViewController" bundle:nil];
[self presentModalViewController:aMessageViewController animated:YES];
[aMessageViewController release];

}

如果您使用导航控制器,则可以使用 self.navigationController.......也。

于 2012-10-10T14:03:37.427 回答