Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 自定义子视图(如AlertView)导航流(委托)_Objective C - Fatal编程技术网

Objective c 自定义子视图(如AlertView)导航流(委托)

Objective c 自定义子视图(如AlertView)导航流(委托),objective-c,Objective C,我有一个MainViewController,它添加了一个CustomModalViewController作为子视图 调用委托函数CustomModalClickedButtonIndex时,MainViewController导航应按下NextView 正在从SuperView中正确地删除CustomModal,但是出现了一个问题,因为没有推送下一个视图 MainViewController.m ... @implementation MainViewController - (IBAc

我有一个MainViewController,它添加了一个CustomModalViewController作为子视图

调用委托函数
CustomModalClickedButtonIndex
时,
MainViewController
导航应按下
NextView

正在从SuperView中正确地删除CustomModal,但是出现了一个问题,因为没有推送下一个视图


MainViewController.m

...
@implementation MainViewController

- (IBAction)btnShowCustomModal:(id)sender
{
    // Add the CustomModal as a SubView
    CustomModalViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomModal"];
        viewController.delegate = self;
        [self.navigationController addChildViewController:viewController];
        [viewController didMoveToParentViewController:self];
        [self.navigationController.view addSubview:viewController.view];
}

#pragma mark - CustomModalViewControllerDelegate
- (void)customModalClickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        // Left Button
    }
    else if (buttonIndex == 1) {
        // Right Button
    }

    // Try to push the NextView. It's not working properly.
    UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NextView"];
    [self.navigationController pushViewController:viewController animated:YES];
}
...
@end
#import "CustomModalViewController.h"

@interface CustomModalViewController ()

@end

@implementation CustomModalViewController

- (IBAction)btnLeft:(id)sender
{
    // Close the Modal and return the delegate method.
    [self.view removeFromSuperview];

    [self.delegate customModalClickedButtonAtIndex:0];
}

- (IBAction)btnRight:(id)sender
{
    // Close the Modal and return the delegate method.
    [self.view removeFromSuperview];

    [self.delegate customModalClickedButtonAtIndex:1];
}

@end


CustomModalViewController.h

#import <UIKit/UIKit.h>

@protocol CustomModalViewControllerDelegate <NSObject>

- (void)customModalClickedButtonAtIndex:(NSInteger)buttonIndex;

@end


@interface CustomModalViewController : UIViewController

@property (weak, nonatomic) id <CustomModalViewControllerDelegate> delegate;

@end

RemoveFromSuperview将清理视图,并且不保证以后执行。所以代码永远不会被调用

你会想做两件事中的一件。 1让调用视图句柄关闭它,因为它是添加它的那个,所以这样做并不是坏事。 2首先调用您的代码,并调整顺序以确保所有代码仍然有效