简体   繁体   English

loadView()没有被调用

[英]loadView() no called

I have a UIViewController calling another view Controller with a defined loadView method. 我有一个UIViewController用定义的loadView方法调用另一个视图控制器。 I've been trying many options without success to solve the problem of the loadView method not called. 我一直在尝试许多选项而未成功解决未调用的loadView方法的问题。

Any help is appreciated. 任何帮助表示赞赏。

Thanks. 谢谢。 MArcos MArcos

Caller UIViewController 呼叫者UIViewController

#import "MyAlbumViewController.h"
@interface ViewController : UIViewController
@end

implementation 履行

#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}

- (void)viewDidAppear:(BOOL)animated{

    UIViewController*albumVC = [[MyAlbumViewController alloc] init];

    [self.navigationController pushViewController:albumVC animated:YES];


}
@end

Called UIViewController 叫做UIViewController

@interface MyAlbumViewController : NIToolbarPhotoViewController <NIPhotoAlbumScrollViewDataSource>

@end

Implementation 履行

#import "MyAlbumViewController.h"

@implementation MyAlbumViewController

- (void)loadView{

    [super loadView];

    self.photoAlbumView.dataSource = self;

    // Set the default loading image.
    self.photoAlbumView.loadingImage = [UIImage imageWithContentsOfFile:
                                        NIPathForBundleResource(nil, @"NimbusPhotos.bundle/gfx/default.png")];

    self.title = NSLocalizedString(@"Loading...", @"Navigation bar title - Loading a photo album");

    [self loadAlbumInformation];
}...

The idea of loadView is to completely override the method, and not call super loadView的想法是完全覆盖该方法,而不是调用super

What you are doing is exactly what the viewDidLoad method is for, it doesn't matter if you loaded it from a nib file or whatever 您正在执行的操作正是viewDidLoad方法的用途,无论您是从nib文件还是其他文件加载它都没关系

And I quote from your own post, in your ViewController.m 我引用您在ViewController.m的帖子

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}

I was pushing view controller with: 我用以下方法推动视图控制器:

 [self.navigationController pushViewController:albumVC animated:YES];

I just changed to: 我只是更改为:

[self presentViewController:albumVC animated:YES completion:nil];

UIViewController Navigation Controller UIViewController导航控制器

navigationController The nearest ancestor in the view controller hierarchy that is a navigation controller. navigationController在视图控制器层次结构中最接近的祖先,它是导航控制器。 (read-only) (只读)

@property(nonatomic, readonly, retain) UINavigationController *navigationController Discussion If the receiver or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. @property(非原子的,只读的,保留的)UINavigationController * navigationController讨论如果接收者或其祖先之一是导航控制器的子代,则此属性包含拥有的导航控制器。 This property is nil if the view controller is not embedded inside a navigation controller. 如果视图控制器未嵌入在导航控制器内部,则此属性为nil。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未调用UIViewController的loadView - loadView of UIViewController not called [super loadView] 是否应该从 loadView 调用? - Should [super loadView] be called from loadView or not? loadview方法被多次调用 - loadview method is called several times loadview被称为无限次 - loadview getting called infinite times 在iOS上,如何调用applicationDidBecomeActive,loadView和viewDidLoad? - On iOS, how do applicationDidBecomeActive, loadView, and viewDidLoad get called? 确保在调用loadView之前完全设置了UIViewController - Ensuring that a UIViewController is fully set up before loadView is called iOS 5不会在第二次调用loadView时自动旋转视图 - iOS 5 not autorotating view when loadView is called the second time Three20:通过TTNavigator恢复时没有调用loadView和viewDidLoad - Three20: loadView and viewDidLoad not called when restoring through TTNavigator 即使我们不像其他 ViewController 生命周期方法那样在 viewcontroller 中覆盖它,是否也会调用 loadView? - does loadView get called even if we don't override it in viewcontroller like the other ViewController lifecycle methods? 单元测试(Kiwi):在调用loadView和viewDidLoad之后,属性在测试中总是为零 - Unit testing (Kiwi): Property is always nil in test after loadView and viewDidLoad are called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM