2

我是 Objective c 编程的新手,我正在制作一个应用程序。我正在使用 osx 10.8.4 和 xcode 4.6。我试图在单视图应用程序中(模态)从一个视图控制器到另一个视图控制器。我已经给出了segue 的segue 标识符并在storyboard 中放置了一个segue。但是,当我尝试 segue 时,控制台会显示:

 Warning: Attempt to present <UIViewController: 0x74acff0> on <ViewController: 0x82b25a0> whose view is not in the window hierarchy!

这是我的第一个视图控制器 .m 文件的代码(包含要转义的代码):

 Viewcontroller.m:

 #import "ViewController.h"
 #import "hackScreen.h"
 #import "AppDelegate.h"
 #import <RevMobAds/RevMobAds.h>

 @interface ViewController ()

 @end

 @implementation ViewController

 - (void)viewDidLoad
 {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

- (IBAction)hackStarter:(id)sender {

NSString *checker = [_redBoulderRepublic text];
int soLong = [checker length];

UIAlertView *wrongNumber = [[UIAlertView alloc]
                            initWithTitle:@"Invalid number"
                            message:@"Please enter a valid phone number"
                            delegate:nil
                            cancelButtonTitle:@"dismiss"
                            otherButtonTitles:nil];

if (soLong == 10){
    [self performSegueWithIdentifier:@"SegueOne" sender:sender];

}
else{
   [wrongNumber show]; 
}

 }
 - (void)dealloc {
[_redBoulderRepublic release];
[super dealloc];
}
 - (IBAction)keyboardKiller:(id)sender {
[_redBoulderRepublic resignFirstResponder];
 }



@end

还有我的 .h 文件:

 Viewcontroller.h:

#import <UIKit/UIKit.h>
#import <RevMobAds/RevMobAds.h>
#import "AppDelegate.h"
#import "hackScreen.h"
@interface ViewController : UIViewController
- (IBAction)hackStarter:(id)sender;
@property (retain, nonatomic) IBOutlet UITextField *redBoulderRepublic;
- (IBAction)keyboardKiller:(id)sender;


@end
4

1 回答 1

4

该错误意味着您ViewController当前未显示,但您正在尝试对另一个控制器执行 segue。为了执行从一个视图控制器到另一个视图控制器的转换,第一个视图控制器需要是可见的(或至少添加到视图层次结构中)。

换句话说,您是在显示hackStart的实例之前调用的ViewController

于 2013-08-24T21:31:53.723 回答