自从实现用于侧架导航的库(https://github.com/SocialObjects-Software/AMSlideMenu)以来,我遇到了导航/ ViewController层次结构问题。这个库的实现可以与演示ViewControllers一起使用(可以在链接的Github页面上看到),但是当我调整它以包含我之前一直在使用的实际ViewControllers时(它们本身也可以自己工作),我的导航流程崩溃了。
我的应用程序的ViewControllers目前的结构如下:
在实现货架导航库之前,我的故事板只包含以下ViewControllers,而且我没有遇到问题:
在ItemsTable ViewController中,如预期的那样,用户会看到他们添加的项目的TableView。就像之前一样(我们现在仍然很擅长),用户点击ItemsTable ViewController中的“添加”按钮,然后转到AddPhoto ViewController。用户选择照片并将其带到AddItemDetails ViewController,用户可在其中为此照片添加标题。
但是,这是它崩溃的地方。
项目上传本身实际上有效,因为新添加的项目显示在我的Parse数据浏览器中,以及我关闭并重新启动应用程序后的ItemsTableView中。但是当我单击按钮在AddItemDetails ViewController中添加Item时,我没有带我回到TableViewController,而是更新了包含新Item的项目列表,我被带回到UICameraPicker,在那里我陷入了一个循环添加项目的照片,但永远不会回到TableViewController来查看它们。当我单击UICameraPicker上的取消按钮时,我收到以下警告消息:
2014-05-31 23:04:26.312 GetGa[6872:90b] Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x10b637f60>.
AddPhoto ViewController (我陷入了循环中)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"givePhotoToGiveDetailsSegue"]){
if ([segue.destinationViewController isKindOfClass:[JFGiveItemDetailsVC class]]){
JFGiveItemDetailsVC *targetVC = segue.destinationViewController;
targetVC.giveItemImage = self.giveItemImage;
}
}
}
-(void)viewDidAppear:(BOOL)animated
{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerEditedImage];
if(!image) image = info[UIImagePickerControllerOriginalImage];
self.giveItemImage = image;
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"givePhotoToGiveDetailsSegue" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self.navigationController popToRootViewControllerAnimated:YES];
}
AddItemDetails ViewController (应该将我发送回ItemsTable ViewController)
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSString *nameForGiveItem = self.giveItemTitleTextField.text;
NSData *giveItemImageData = UIImagePNGRepresentation(self.giveItemImage);
PFFile *giveItemImageFile = [PFFile fileWithName:nameForGiveItem data:giveItemImageData];
PFObject *giveItemPhoto = [PFObject objectWithClassName:@"giveItemPhoto"];
giveItemPhoto[@"imageOwner"] = [PFUser currentUser];
giveItemPhoto[@"imageName"] = nameForGiveItem;
giveItemPhoto[@"imageFile"] = giveItemImageFile;
[giveItemPhoto saveInBackground];
PFObject *giveItem = [PFObject objectWithClassName:@"giveItem"];
giveItem[@"giveItemTitle"] = self.giveItemTitleTextField.text;
giveItem[@"giver"] = [PFUser currentUser];
[giveItem setObject:giveItemPhoto forKey:@"giveItemPhoto"];
[giveItem saveInBackground];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
return YES;
}
答案 0 :(得分:0)
我遇到了同样的问题。这就是我所做的,在你的- (void)viewDidAppear:(BOOL)animated
函数中写下这个:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
MJLoginViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:loginController animated:YES];
如果您使用的是iOS 7,那么storyboardWithName:@"Main"
对您来说就是一样的。
MJLoginViewController是我的Main.Storyborad和instantiateViewControllerWithIdentifier:@"LoginViewController"
中的视图控制器的类,您应该在这里编写故事板ID名称。如果你没有给一个人分配一个。
运行,它将起作用。