ios - 以编程方式启动和关闭 UINavigationView

标签 ios objective-c

如果用户点击 TableView 中的行,我有很多关于显示 View 的选项(3 个选项)。 我像这样启动新的 ViewController:

 ImageViewNIB *dest = [[ImageViewNIB alloc] init];
        [self presentViewController:dest animated:YES completion:nil];

当它出现时,我想通过单击按钮将其关闭。我显示了 NIB 文件中的新 View 。

@interface ImageViewNIB : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@property (strong, nonatomic) IBOutlet UIBarButtonItem *close;


@end



#import "ImageViewNIB.h"

@interface ImageViewNIB ()

@end

@implementation ImageViewNIB

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

- (IBAction)backBtnUserClicked:(id)object {

    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        NSLog(@"KONCZE");
    }];
}
@end

并从 Nib 查看:

enter image description here

一切都以编程方式启动和创建,其中还有 UINavigationBar 和按钮。 NaviationBar 中的按钮是 UIBarButtonItem 类型,但我已使用“.M”类中的方法将其与 IB 连接起来。它不显示 NSLOG,并且在录制时 View 不会关闭。如何以编程方式代替 STORYBOARD 制作此 segue?

最佳答案

您没有 UINavigationController。因此,您应该将 dismiss 方法发送给自己:

[self dismissViewControllerAnimated:YES completion:^{
    NSLog(@"KONCZE");
}];

关于ios - 以编程方式启动和关闭 UINavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24790273/

相关文章:

ios - 模拟所有物理按钮,如 iOS 7 上的主页按钮压力(越狱)

objective-c - 如何在不使用 iOS sdk 中的任何仪器的情况下检测心率?

iphone - 重复scrollView动画

iphone - 将 NSString 传递给 Webview

ios - 从 NSMutableArray 对象属性中删除重复对象?

ios - 如何从命令行在模拟器上构建和运行 xcodeproj?

ios - 使用 UIBezierPath 在 Swift 中制作旭日形

ios - 有没有办法在 SpriteKit 中叠加帧?

ios - 在 Parse 中,我如何编写一个查询来为我提供带有 id 列表的所有对象?操作系统

ios - 如何使用 Alamofire 使用以下参数进行 API 调用(Mashape)?