2013-09-22 123 views
0

调试试图从一个模式的看法要到普通视图 - 控制(PBSViewControllerDataDetail.h)时,我的应用程序时,我得到一个断言失败错误(不是原来的观点,即呈现控制器模式的看法从模态视图呈现视图 - 控制给错误

本质上讲,我试图做的是:

ViewController1,开放模式的看法,做一个异步请求。当它返回时,将用户发送到第二个普通视图控制器,该视图控制器将向用户呈现在模态视图内获得的数据。

其他一切正常工作,直到模态显示第二个视图控制器。我得到的错误(1号线是从改掉呈现第二VC的方法中我的NSLog输出)

2013-09-22 07:24:11.410 PBSDashboard[566:1303] flipToDataView->Send user to PBSViewControllerDataDetail 
2013-09-22 07:24:11.411 PBSDashboard[566:1303] *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIWindowController.m:211 

请注意:我这个项目中使用NavigationViewController,并考虑重新启动整个很多,但使用一个,但此刻我只是想了解如何从Modal转到正常的ViewController,而不是原来的。

我已经尝试清理目标,重新创建第二个VC从头开始,都没有成功。

代码片段

PBSRequestViewController.h

#import <UIKit/UIKit.h> 
#import "Unirest.h" 
#import "PBSDaySales.h" 

@class PBSRequestViewController; 

@protocol PBSRequestViewControllerDelegate 
    - (void) requestViewControllerDidFinish:(PBSRequestViewController *)controller; 
@end 

@interface PBSRequestViewController : UIViewController 

@property (weak, nonatomic) IBOutlet id <PBSRequestViewControllerDelegate> delegate; 
@property (weak, nonatomic) IBOutlet NSString *calendType; 
@property (weak, nonatomic) IBOutlet NSString *targetDate; 
@property (weak, nonatomic) IBOutlet UILabel *messageLabel; 


- (void) runUnirestRequest:(NSString*)urlToGet; 
- (void) loadDefaultSettings; 
- (NSString*) buildRequestUrl:(NSString*)serverUrl withPort:(NSString*)serverPort withCalenderType:(NSString*)calendarType withDateStringParameter:(NSString*)selectedTargetDate; 

- (IBAction)btnBack:(id)sender; 

- (PBSDaySales*) deserializeJsonPacket:(NSDictionary*)httpJson; 
- (void)createActivityIndicator; 
- (void)flipToDataView; 

@end 

PBSRequestViewController.m(只是调用了第二个VC功能)

// Method will forward the user on to the data view. 
// Used after the uniRestRequest is completed and data exists. 
- (void) flipToDataView 
{ 
    NSLog(@"flipToDataView->Send user to PBSViewControllerDataDetail"); 
    PBSViewControllerDataDetail *dataVc = [[PBSViewControllerDataDetail alloc] initWithNibName:@"PBSViewControllerDataDetail" bundle:nil]; 

    dataVc.daySalesData = daySalesFigures; 

    [self presentViewController:dataVc animated:YES completion: nil]; 
} 

PBSViewControl lerDataDetail.h

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

@interface PBSViewControllerDataDetail : UIViewController 
    @property (weak, nonatomic) PBSDaySales *daySalesData; 
@end 

PBSViewControllerDataDetail.m

#import "PBSViewControllerDataDetail.h" 

@interface PBSViewControllerDataDetail() 

@end 

@implementation PBSViewControllerDataDetail 

@synthesize daySalesData; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    NSLog(@"View loaded"); 
} 

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

@end 

PBSAppDelegate.m

#import "PBSAppDelegate.h" 

#import "PBSViewController.h" 

@implementation PBSAppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[PBSViewController alloc] initWithNibName:@"PBSViewController_iPhone" bundle:nil]; 
    } else { 
     self.viewController = [[PBSViewController alloc] initWithNibName:@"PBSViewController_iPad" bundle:nil]; 
    } 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

回答

0

从模式到 '正常' 的,你应该呈现“正常'模式控制器后面的控制器(通常位于根控制器中)然后解散模态。有一个导航控制器作为窗口的根视图控制器可以让生活更轻松,因为它可以是模式的主机。在任何时候你都不应该试图使用从模态到“正常”的过渡,而是始终忽视模态。模式是在屏幕层的概念上不同的水平,如果这是有道理的...

+0

谢谢,我会重新推翻使用导航控制器的项目。似乎我从一开始就把这整个事情做错了。干杯 –

相关问题