presentModalViewController没有出现在'Simple'App中

时间:2010-01-08 16:57:55

标签: iphone-sdk-3.0

我意识到我仍然遇到这个问题的新手。我正在尝试在我正在进行的项目中呈现一个模态窗口而且它没有出现。我的解决方案是创建一个绝对的基本项目并让它首先在那里工作,所以我会清楚地理解我的问题,但我甚至无法解决这个问题:(

我在applicationDidFinishLaunching中将一个ViewController添加到MainWindow。在这个ViewControllers XIB中,我有一个按钮。 ViewController具有以下标题:

#import <UIKit/UIKit.h>
#import "ModalView.h"

@interface ViewBasedViewController : UIViewController {
    ModalView *modalView;
}

- (IBAction)dooooIt :(id)sender;

@property (nonatomic, retain, readonly) ModalView *modalView;

@end

方法:

#import "ViewBasedViewController.h"

@implementation ViewBasedViewController

@synthesize modalView;

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {
}


- (void)dealloc {
    [super dealloc];
    [modalView release];
}

- (ModalView *)modalView {
    if (modalView == nil) {
        modalView = [[ModalView alloc] initWithNibName:@"ModalView" bundle:nil];
    }
    return modalView;
}

- (IBAction)dooooIt :(id)sender {

    [self.navigationController presentModalViewController:modalView animated:YES];

}

@end

我显然错过了一些非常简单的事情,我相信在这个阶段我的耳朵之间:)

有没有人想让一个可怜的家伙摆脱苦难?

非常感谢

克里斯

2 个答案:

答案 0 :(得分:0)

您是否已将按钮连接到IBAction?控制 - 在您的按钮中将Interface Builder拖动到XIB文件中的“文件所有者”图标,然后在那里选择“dooooIt”方法。重新编译,您的代码应按预期执行。

答案 1 :(得分:0)

对于那些可能遇到这个问题而且和我一样困惑的人,我倒下了解决方案。 dooooIt方法存在两个问题:

- (IBAction)dooooIt :(id)sender {
    [self presentModalViewController:self.modalView animated:YES];

}

我在引用modalView属性时应该包含'self'(否则它是nil),我不应该引用navigationController,因为我没有连接。

希望这对你们任何人都有帮助(令人惊讶的是一杯葡萄酒可以做到的!)