viewDidLoad not Called for UIViewController with UIScrollView and UIPageControl - iphone

I am trying to add a page with a UIScrollView and UIPageControl to my app. I am making the call to the new class from a UITableView as below.
MultiPageViewController *mpvc = [[MultiPageViewController alloc]initWithNibName:#"MultiPageViewController" bundle:[NSBundle mainBundle]];
[[self navigationController]pushViewController:mpvc animated:YES];
The viewDidLoad function is never called, thus my UIScrollview and UIPageControl are never initialized. When I go along further and call viewWillAppear these objects are both still nil. Further the view never appears only a white screen. Below is the code from initWithNibName and viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(#"initWithNibName returned self != null");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"View did load called");
}
Thanks for your help in advance.

Related

How to create viewController in PhoneGap to work with main view

I want to open file with [UIDocumentInteractionController presentPreviewAnimated];
I've created view controller
#interface FileViewController : UIViewController <UIDocumentInteractionControllerDelegate>
#end
#import "FileViewController.h"
#interface FileViewController ()
#end
#implementation FileViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And trying to preview the file
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
vController = [[FileViewController alloc] init];
controller.delegate = vController;
[controller presentPreviewAnimated:YES];
And get error:
Warning: Attempt to present <QLPreviewController: 0x1e56e0a0> on <FileViewController: 0x1ec3e000> whose view is not in the window hierarchy!
I may set root view controller
[[[[UIApplication sharedApplication] delegate] window] setRootViewController:vController];
But I dont want to use new view. I need to use the PhoneGap's main view. How can I do this?
The problem is solved
CDVViewController* mainController = (CDVViewController*)[ super viewController ];
[mainController addChildViewController:vController];

Rogue Zombie on dealloc of ViewController

In Xcode, start a new master-detail project. Call it 'Test'.
Add a new 'File' to it. Make it a UIViewController file with XIB. Call it TestViewController.
Modify your MasterViewController code in the insertNewObject: method to say this:
-(void)insertNewObject:(id)sender
{
TestViewController *initViewController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
[self.navigationController pushViewController:initViewController animated:YES];
[initViewController release];
}
Now add a dealloc method into TestViewController.m and simply call [super dealloc];
Put a breakpoint here and run the app. All should run OK.
However, if you Enable Zombie object, you may get a *** -[TestViewController class]: message sent to deallocated instance 0x7484f20 error when stepping over [super dealloc].
Do you get this as well? I'm on iOS6.0 simulator and came across it trying to debug an issue which has led me to this.
Thoughts appreciated. Is it an iOS bug? Or a simulator bug?
Added TestViewController Code for 'clarity'
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc
{
// Zombie here???
[super dealloc];
}
I guess that your TestViewController has outlets and properties. If any of those properties/outlets are over released it will cause this error. Make sure that [super dealloc] is the last line on you dealloc method too

why -(id)init not see my objects;

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
preview.text = "hello";
}
return self;
}
Preview it's a simple UILabel;
Just because you created your view controller from a nib doesn't mean it immediately loads it.
You need to put any code that requires ui components to be created in viewDidLoad i.e.
- (void)viewDidLoad {
preview.text = "hello";
}
If you check, preview will be nil inside your init method so setting text on it won't work!
because your iboutlets (the UI components) are loaded in the viewdidload method
you can't acces them in the init

Unable to load view on button press iPhone

I am unable to load the next view on button press. I have created a button and attached the checkButtonPress action to the button in the IB. But when I press the button on the simulator the next view (ViewOne.xib) do not load. When I tried to debug the code; it is printing the NSLog(#"View One");written in the if statement below which means the code is reaching to that point but the next view is not loading. I have already created the ViewOne .h, .m .xib files. Following is the code written in check1ViewController.m implementation file:
#import "check1ViewController.h"
#import "ViewOne.h"
#implementation check1ViewController
-(IBAction) checkButtonPress: (id) sender{
int button = [sender tag];
if(button==1)
{
NSLog(#"View One");
ViewOne *tempObj = [[ViewOne alloc]initWithNibName:#"ViewOne" bundle:nil];
[self.navigationController pushViewController:tempObj animated:YES];
[tempObj release];
}
else if(button==2)
{
NSLog(#"View Two");
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (void)dealloc {
[super dealloc];
}
#end
The code is running fine with no errors or warnings.
Any suggestions if I am missing any part in the IB or in the code to be written or do need to override any method in any of the file ... or did I misplace IBAction before any other method
Sorry but I am new to iPhone dev so not sure what I did wrong ?
Thanks in advance
You application is not having navigation controller so add next view on window for this make object of AppDelegate class and then access window to addView.
YourAppDelegate *obj=(YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[obj.window addSubView:viewController.view];

Customising UITabBarItems in their controllers?

In previous applications I have customised my tabBarItems by overriding init (see below)
- (id)init {
self = [super init];
if(self) {
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setTitle:#"ONE"];
}
return self;
}
After looking at the Xcode templates I am now thinking that I would be better to add this customisation to initWithNibName:bundle: instead.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setTitle:#"ONE"];
}
return self;
}
does this make sense, it seems like it does to me, but I just wanted to check?
Gary
It depends on whether you load your controller from a Nib (xib) file or not (and so you do all the work programmatically in the init) I guess