尝试从模态视图转到普通视图控制器 ( PBSViewControllerDataDetail.h )时调试我的应用程序时出现断言失败错误(不是呈现模态视图的原始视图控制器)
基本上我想做的是:
ViewController1,打开模态视图并执行异步请求。当它返回时,然后将用户发送到第二个普通视图控制器,该控制器将向用户呈现在模态视图中获得的数据。
在模态尝试呈现第二个视图控制器之前,其他一切都有效。我收到错误消息(第一行是我在尝试呈现第二个 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 的普通 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;
}