Program received signal EXC_BAD_ACCESS : Simple Navigation - iphone

This is really basic. But I have no idea where I am going wrong.
I am on the ARC mode and all I have done is written the following code in my AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function
homePage *hp = [[homePage alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:hp];
The home page gets loaded up correctly and there is a button on the homePage which when clicked should trigger a pressedPlay: wired up correctly in the .xib. But as soon as the button is clicked the program crashes with the error: EXC_BAD_ACCESS. Any help please?

This usually means something had a reference count of zero and then you tried to use it.
I bet it is something to do with whatever your button touch event is trying to process. Step through the code and see exactly at what point the crash happens.

Try this
homePage *hp = [[homePage alloc] initWithNibName:#"homePage" bundle:nil];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:hp];
And follow naming conventions instead of homePage it should be HomePage.

I found a fix to the problem. With ARC the view to be pushed into the navigation controller must have a strong property associated with it, otherwise it is released.

Related

upgrading iPhone app to universal and now using splitview

I have an iPhone app that works and is getting used. I now want to upgrade this application to a Universal app. Taking that into consideration I've already made changes, like creating another MainWindow.xib for the iPad, which i've gotten to work. I've pretty much got the whole iPhone App working for the iPad. The next step I needed to take was to convert my Events Calendar to be a splitview. As far as I can tell, I'm don't need to change any of the logic in the two controllers I already have (CalendarViewController and CalendarDetailViewController).
That being said, what is the best way to make them work on a splitview? Is it possible to have the splitview use these two controllers (since a splitview has two controllers by default, a TableViewController and a ViewController)? Would I then need to create another appDelegate or something to pass all the right information back to the MainWindow.xib? Or am I going to need to create a new SplitViewController? and if so, how would I then combine all the logic from my two Calendar Controllers?
Any help would be greatly appreciated!!
Assuming you are using StoryBoard: drag a SplitViewController into the iPad StoryBoard. Also be sure your two desired UIViewControllers are in there. Control-click on the SplitViewController and drag over to each UIViewController and select you how want it set.
I know it's a bit late to answer this question but if someone needs...
You don´t need another appDelegate, you just need to check (in appDelegate) whether your device is an iPad, and then set an array of view Controllers with the MasterVC and the DetailVC. Otherwise you will set your rootViewController as you are doing now in the iPhone app.
It would be something similar to that:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[...]
YourMasterVC *mvc =
[[YourMasterVC alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNav =
[[UINavigationController alloc] initWithRootViewController:mvc];
YourDetailVC *dvc = [[YourDetailVC alloc] init];
cvc.detailViewController = dvc;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// On iPad
UINavigationController *detailNav =
[[UINavigationController alloc] initWithRootViewController:dvc];
UISplitViewController *svc = [[UISplitViewController alloc] init];
svc.delegate = wvc;
svc.viewControllers = #[masterNav, detailNav];
self.window.rootViewController = svc;
} else {
// On iPhone
self.window.rootViewController = masterNav;
}
[...]
}

How to remove from this Debugger warning [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Getting “Using two-stage rotation animation” warning with UIImagePickerController
In my iphone app i have a login screen after loging in i am navigating to a class ( i have tab barcontroller with 5 tabs here)
like this i am programmatically creating the tabbar
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *arrControllers = [[NSMutableArray alloc] initWithCapacity:5];
//Add PunchClock to tab View Controller
PunchClock* objPunchClock = [[PunchClock alloc] initWithTabBar];
NavigationController = [[UINavigationController alloc] initWithRootViewController:objPunchClock];
NavigationController.navigationBar.tintColor = [UIColor brownColor];
[arrControllers addObject:NavigationController];
[NavigationController release];
[objPunchClock release];
tabBarController .viewControllers = arrControllers;
[arrControllers release];
[self.view addSubview:[tabBarController view]];
after logging in while navigating to this class i am getting this Debugger warning
2012-07-07 12:09:27.988 WorkForce[1475:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
2012-07-07 12:09:28.074 WorkForce[1475:207] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
what is it mean,,,how to remove this warning? please help me out
I have no idea what that error message means but when you get such a specific error message, it is often helpful to do a search with the entire error message in quotes to see if anyone else has encountered it.
Apparently they have. Please report back and tell us what it means.
The two-halves animation methods like willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: and willAnimateSecondHalfOfRotationToInterfaceOrientation:duration: are an older approach. If you've implemented these methods, they should be removed so that the one-step scheme (in this case, willAnimateRotationToInterfaceOrientation:duration:) can be used.

iPhone :: Objective-C - AddSubview in my initial UIViewController ViewDidAppear

Hihi all,
This could very well be a silly question. I would like to navigate to my "Login View" upon the launching of my application. My current tries:
In my first UIViewController's viewDidAppear method, perform a [self presentModalViewController:LoginView animated:YES], this works, but the screen shows my main UIView first, then slide my LoginView from bottom to top. I can't find a way to perform it without the animation.
In my first UIViewController's viewDidAppear method, perform a [self.view addSubview:LoginView.view], it ends up with exc_bad_access error.
Basically, my requirement is to perform certain checks upon starting of the application, if a login is required, the application shall display the LoginView, otherwise, it should stay as my main UIView.
Please advice what is the best way of achieving this, instead of the above two silly methods. Thanks in advance!
:)
How about trying it in **- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {**
example :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
LoginViewController *aLoginViewController = [[LoginViewController alloc] init];
[self.navigationController presentModalViewController:aLoginViewController animated:NO];
[aLoginViewController release];
return YES;
}
your 1st step is a good way..
but to stop animation, its very simple. Set animated to NO.
[self presentModalViewController:aLoginViewController animated:NO];
once ur done with ur validation, just dismiss this aLoginViewController.
Instead of -viewDidAppear, it sounds like you want to use -viewWillAppear:, which will allow you to present your login controller before the initial view is displayed.
-presentModalViewController:animated is the right method to display your login controller's view.

Problem with getting a modalViewController to appear

I've been fighting with this for hours. I've searched around everywhere and just can't seem to find the solution to my problem. I'm pretty sure I'm just lacking some key concepts here.
My AppDelegate (didFinishLaunching) basically sets up my window and invokes RootViewController:
// create our window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setBackgroundColor:[UIColor blackColor]];
// create our rootviewcontroller
RootViewController *controller = [[RootViewController alloc] init];
// add our rootviewcontroller's view to our window
[window addSubview:controller.view];
// controller is now owned by window's view
[controller release];
// show us to the world
[window makeKeyAndVisible];
When I add controller.view as window's subview, my understanding is that RootVC's loadView will automatically get called.
In RootVC loadView, I create a tabBarController, each tab having a navigationController and it's own viewController. All that is working fine.
In RootVC viewDidLoad, I'm checking to see if this is the first time a user is running this app, and if so, I want to throw up a modal welcome screen. This is the part I'm having trouble with.
I'd like to keep as much code out of the RootVC's viewDidLoad method, and ideally would be able to accomplish what I want with this:
WelcomeViewController *welcome = [[WelcomeViewController alloc] init];
[self presentModalViewController:welcome animated:true];
[welcome release];
Obviously this isn't working. WelcomeVC's loadView hasn't been run yet because I haven't explicitly set it's view property. I've played around with a bunch of different solutions (welcome.view - [[UIView....], using WelcomeVC's init method to set self.view) but I just can't seem to get that modal to pop up.
How should I accomplish what I'm looking for? What are the best practices, and what's the best solution to keep my code tight and tidy?
I'm stuck, so hopefully your solution will allow me to continue developing my app!
Although the problem is not so simple, the solution is. You have to wait until the main view appears. So check the condition and present your modal view in viewDidAppear method, not in viewDidLoad method.

App stalls - no crash, no error

It is worth noting that this part of the app (this option from the main menu) was working perfectly before. I then programmed the next option from the main menu, and now this one is not working anymore.
I know the code I've written works, but there is something wrong with either the class or the xib, because it worked when I switched it to call a different class/xib from:
UIViewController *nextController = [[OneMethodController alloc] initWithNibName:#"OneMethodController" bundle:nil];
to:
UIViewController *nextController = [[SecondMethodController alloc] initWithNibName:#"SecondMethodController" bundle:nil];
When I try to load the first class/xib (which used to work, as I said), the app just stalls indefinitely. There is no error and the app does not crash.
Any ideas? THANKS!!
Note that *nextController should most likely be initialized as
SecondMethodController *nextController = [[SecondMethodController alloc] init . . .
And not as
UIViewController *nextController = [[SecondMethodController alloc] init . . .
The issue was not with the XIB but with the viewDidLoad of that XIB's class. Thanks #cool_me5000 for your help with this.