开发者

How to have the constructor method and how to call it when the instance is created?

I have created a navigation-based application. In that, I have created MyTableViewController using uiviewcontroller.class.

#import "RootViewController.h"

#import "MyTableViewController.h"


@implementation RootViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    MyTableViewController *tableViewCon开发者_运维问答troller = [[MyTableViewController alloc] init];

}

@end


#import "MyTableViewController.h"


@implementation MyTableViewController

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

    NSLog(@"sedfsdsd");
}

@end

I don't want to show the view when the instance is created. I want to call the constructor method. I don't know how to do it. Please help me out.


@Caroline have described very good.

A normal method of your class could serve your purpose and you can name that something ViewContruction and define it in your MyTableViewController class.

-(void) ViewContruction
{
   //Create all your views here

   //Add that to the self.view of your controller
}

Call the above function explicitly on the instance of your view controller.


Just creating a UIViewController instance does not load the view.

If you have something like [self.view addSubview:tableViewController.view] then when that statement is executed, viewDidLoad will get executed.

However, if it's a navigation-based app, then you will need to push the viewcontroller to see it, rather than adding the subview as above.

For example:

        Settings *settingsController = [[Settings alloc] initWithNibName:@"Settings" bundle:nil];
        settingsController.contentSizeForViewInPopover = settingsController.view.frame.size;
        [self.navigationController pushViewController:settingsController animated:YES];
        [settingsController release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜