在尝试从模态视图转到普通视图控制器( PBSViewControllerDataDetail.h )时调试我的应用程序时出现断言失败错误(不是原始视图控制器提供的模态视图)
基本上我要做的是:
ViewController1,打开模态视图并执行异步请求。当它返回时,然后将用户发送到第二个普通视图控制器,该控制器将向用户显示在模态视图中获得的数据。
其他一切都有效,直到模态尝试呈现第二个视图控制器。我得到了错误(第一行是我的NSLog输出,来自试图呈现第二个VC的方法)
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];
}
PBSViewControllerDataDetail.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)
要从模态转换为“正常”,您应该在模态控制器后面(通常在根导航控制器中)呈现“正常”控制器,然后解除模态。将导航控制器作为窗口的根视图控制器可以使生活更轻松,因为它可以是模态的主机。在任何时候你都不应该尝试使用从模态到“正常”的过渡,它始终是对模态的忽略。如果有意义的话,模态在屏幕层中的概念上是不同的级别......