Custom UIViewController hiding properties - ios

TLDR
Properties are not showing on a UIViewController that I was able to access when working on this project yesterday. This is not as simple as how do I set a property on a VC? I can not see the properties of the VC.
The Situation
A custom UIViewController (A) pushes to a second UIViewController (B), pushes to a third UIViewController (C)
//programmatically calling a push to the next view in A to B to C, example code from B to C.
EnterFinalHRViewController * finalHeartRate = [self.storyboard instantiateViewControllerWithIdentifier:#"EnterFinalHeartRateController"];
finalHeartRate.lanes = _lanes;
[self.navigationController pushViewController:finalHeartRate animated:YES];
The NSMutableArray, lanes, gets passed along twice. Not a problem.
When I arrive in VC(C) the debugger reads:
A self = (EnterFinalHRViewController *) #"0 objects" 0x15da40c0
V [0]
I have a header file in VC(C) that reads
#import <UIKit/UIKit.h>
#import "SwimTimingViewController.h"
#import "Lane.h"
#interface EnterFinalHRViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UIPickerViewDataSource, UIPickerViewDelegate>
#property (nonatomic, strong) NSMutableArray *lanes;
#end
For Clarity
Lanes is just an example of one property that is passed along.
This is not just trying to set and access a property of a VC across a segue
I've looked everywhere I can, any more links would be appreciated as well.
The Question
Why can't I see any properties of self in the final UIViewController in the debugger, how would one fix it, and or any useful debugging tips.
My Theory
Since upgrading to a new version of xcode, last night, something broke / xcode bug, and I don't know what that is. I am now using Xcode Version 6.1 (6A1052d). I am testing using my iPhone 5c running ios7. (I will be upgrading as soon as everything works 100% in ios7).
Quick shout out to thank all the contributors here at SO and beyond. The help is alway very warmly welcomed.

Related

How do I transition to a different view controller programmatically?

Hey guys I'm trying to get my app to load a new view when a certain method is called. Inside the method I have the code:
ViewController *GameOverViewController = [[ViewController alloc] init];
[self presentViewController:GameOverViewController animated:YES completion:nil];
which is taken straight from How to switch views programmatically in a ViewController? (XCode iPhone).
Anyways, when I try to switch from my view controller called Game to a view controller called GameOverViewController I just get a ton of errors. Mainly
"Unknown receiver 'ViewController'; did you mean 'UIViewController'
And my app crashes. I'm obviously doing something wrong but I have no idea what that is exactly. Do I have to declare the GameOverViewController in my Game.h or in my appDelegate or something?
EDIT: Both view controllers are in the same main.Storyboard file if that matters
The unknown receiver message means that it can't find the class definition for the view controller class called ViewController. Is that really the name of the class you're using for your "game over" view controller? And if so, have you done the #import "ViewController.h" at the start of this .m file?
The fundamental problem is that it cannot find the class called ViewController.
Setting that aside, we don't generally instantiate new view controllers using alloc and init anymore, as that answer may have implied. That was a technique used with NIBs (and only worked if the NIB name matched the class name).
For new developers, I might encourage you to start with storyboards. Any modern tutorial should walk you through how to use storyboards. (Google "iOS storyboard tutorial" and you'll probably get lots of hits.)
If, for example, your storyboard has a scene with a "storyboard identifier" of GameOverViewController, then you might programmatically instantiate it and present it with something like:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"GameOverViewController"];
[self presentViewController:controller animated:YES completion:nil];
Or, if your storyboard had a segue from the current scene to the next scene, you'd make sure that segue had its own storyboard identifier, e.g. GameOverSegue, and then you'd perform it like so:
[self performSegueWithIdentifier:#"GameOverSegue" sender:self];
But find yourself a good introduction/tutorial on storyboards, as stumbling through Stack Overflow for answers will not be a very fruitful exercise.
For historical purposes, it's worth noting that if you were using NIBs, you can use the construct you referenced to in your question (but you'd have to make sure that (a) the class name was right; and (b) you did the #import that class header). And if the destination NIB had a different name than the class, you'd have to do something like:
UIViewController *controller = [[NSBundle mainBundle] loadNibNamed:#"nibname" owner:self options:nil]`;
[self presentViewController:controller animated:YES completion:nil];
But this is all academic unless you're using NIBs. If using storyboards, use one of the above patterns if you need to transition to a new scene programmatically.
You are in over your head. You should slow down and do some more studying or things are going to crash all over the place. I suggest going through a good book on iOS development and doing the exercises.
On to your question:
In the code you posted you're using a class "ViewController". There is no system-defined class "ViewController", although it is a common class name in example projects, and I think some of the project templates in Xcode even create a root view controller with that class name.
The name you give to your variable ("GameOverViewController" in the code above) is local and not really important. That's just a variable name. You can rename it lateForDinner if you want to, and it won't make any difference as long as you change that name everywhere in the scope in which it's defined.
The fact that you're being told that the class "ViewController" is unknown suggests that it hasn't been defined anywhere in your program.
You need an #interface and #implementation section that defines the ViewController class. Usually those will be in files called ViewController.h and ViewController.m, respectively. They might look something like this:
//ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController: UIViewController //Defines it as a subclass of UIViewController
// properties and methods of ViewController defined here
#end
And the .m file:
//ViewController.m
#implementation ViewController
// Implementation of ViewController methods go here.
#end
It's also possible to include the interfaces of multiple classes in a single header file, and the implementations of multiple classes in a single .m file, although I dislike this practice intensely. Keep it simple - one class per .h/.m file pair, with the file names identical to the class name.

Google Analytics for SDK iOS - implementing automatic screen

I want to add google analytics to my application, I followed up the instructions in this link https://developers.google.com/analytics/devguides/collection/ios/v3/#screen-tracking
I did all the instructions, my question is in the last step when I want to measure with a view controller, my view controller .h is :
#interface RootViewController : UIViewController<SectionHeaderViewDelegate, UITableViewDelegate,UIAlertViewDelegate>
in the instructions given in the link above, they said that we have to import #import "GAITrackedViewController.h" and we have to update the header like :
#interface RootViewController : GAITrackedViewController
#end
my question is shall I update the UIViewController from #interface RootViewController : UIViewController<SectionHeaderViewDelegate, UITableViewDelegate,UIAlertViewDelegate>
to
#interface RootViewController : GAITrackedViewController<SectionHeaderViewDelegate, UITableViewDelegate,UIAlertViewDelegate> ????
please help!
Many thanks.
Yes.
You need to change the inheritance from plain UIViewController to the Google tracked view controller and you need to keep all of your protocol information as well (the things in <>)

UIViewController Is Not Working

This behavior is very odd. Every time I create a new project in Xcode 5.0.2 I cannot get it to work fully. Once the Single View Application template (or another) is created - everything seems OK: I have my delegate, storyboards and ViewController. They all run successfully and I can even see newly added UIView's in my Simulator.
Her is my generic code for ViewController:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
UIView *container;
}
#property (nonatomic,retain) IBOutlet UIView *container;
#end
#import "ViewController.h"
#interface ViewController (){}
#end
#implementation ViewController
#synthesize container;
- (void)viewDidLoad{
[super viewDidLoad];
NSLog(#"App loaded");
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
#end
But once I add properties to this controller class and synthesize them, the screen turns black during app running and no views or whatever was added before is ever seen anymore. Just a blank black color screen.
Where is the problem? Please note:
I checked Info*.plist and it points to Storyboard correctly
In delegate my didFinishLaunchingWithOptions returns YES
ViewController has a Initial View Controller checked and is the only one in the storyboard
viewDidLoad prints NSLog message successfully even though nothing is shown
What to check?
Here is a link to the project
A view controller is just that, a controller. The UIViewController's view property is what is visible on the screen (assuming you added it to the screen at some point, storyboard, programatic, xib, etc...)
Check the UIViewcontroller.view.superview. You should be able to get close to what you want.
The view controller properties thing is a complete red herring.
You're using a storyboard for your app, which has all of the relevant details in it. Then, in your app delegate, you've added a load of code to load in a new instance of the view controller and set it as your app's root view controller.
You don't need to do this if you have a storyboard. Just return YES from applicationDidFinishLaunching.. (which was originally the case, since you included the git history in the download!). The initial view controller from your storyboard will already be loaded up. What you've done is to basically ignore the storyboard.

Feeling A Bad Design Layout Using Segues

So I'm on my first iPhone app. I'm actually rather far into it. I have already learned from many mistakes, but I feel I've made an ultimate mistake. I'm using segues to navigate to different views. I get into about 5 segue views deep, which I'm realizing is causing a LOT of allocated memory. In other words, View A calls View B, B segues into C, C into D, etc..From what I understand, by the time I get to D I now have instances of A B C and D open, which does not sound good. I am using delegates for example like below:
Just an example of what I'm doing throughout my app:
First View:
#interface FirstViewController : UIViewController<SecondViewControllerDelegate>
#end
Second View:
#class SecondViewController;
#protocol SecondReviewOrderViewControllerDelegate <NSObject>
- (void)secondViewControllerDidCancel:(SecondViewController *)controller;
#end
#interface SecondViewController : UIViewController<ThirdViewControllerDelegate>
#property (strong, nonatomic) id <SecondViewControllerDelegate> delegate;
#end
Third View:
#class ThirdViewController;
#protocol ThirdReviewOrderViewControllerDelegate <NSObject>
- (void)thirdViewControllerDidCancel:(ThirdViewController *)controller;
#end
#interface ThirdViewController : UIViewController<>
#property (strong, nonatomic) id <ThirdViewControllerDelegate> delegate;
#end
And so on and on onto view 4 and 5.
My question is, if this is wrong, which it seems to be, what is the right way to about navigating views and passing data from one viewcontroller to another? Thanks for any tips.
From what I understand, by the time I get to D I now have instances of A B C and D open, which does not sound good
A view controller, of itself, is a fairly lightweight object, and there is no problem whatever with going many levels deep (e.g. pushing five view controllers onto a navigation controller stack). However, memory and images you may be holding on to are not lightweight, so be sure to implement didReceiveMemoryWarning and take it seriously if it arrives.
A strategy for letting go of large retained memory-hogging stuff in response to didReceiveMemoryWarning is to save it off to disk (if it can't be recreated on demand) and then use lazy initialization to read it back in the next time you are asked for it.

How to transition between views programatically?

I am developing a game, and I would like to transition between several views, e.g. Menu Screen, Game Screen, Game Over Screen etc. What would be the easiest way of doing this? I'm not sure if I should use a view stack as the order that the views are shown is not always reversed.
I assume by "view stack" you mean a UINavigationController?
The easiest way is to keep references to all of the view controllers somewhere, for example I see people use the application delegate a lot, so your application delegate's class extension would look a little like:
#interface AppDelegate ()
#property (nonatomic, strong) UIViewController *rootViewController; //this is what gets set as the window's root VC
#property (nonatomic, strong) UIViewController *mainScreenViewController;
#property (nonatomic, strong) UIViewController *gameScreenViewController;
#property (nonatomic, strong) UIViewController *gameOverScreenViewController;
#end
Assume rootViewController just controls a container view for the rest of the app (You would probably actually be well served putting all this logic into the root view controller though...)
Now anytime you need to show a certain screen, call a method like:
- (void)switchToViewController:(UIViewController *)viewController
{
[self.rootViewController.view.subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
[self.rootViewController.view addSubview:viewController.view];
}
You can now write methods that are named more memorably like -switchToGameOverScreen
- (void)switchToGameOverScreen
{
[self switchToViewController:self.gameOverScreenViewController];
}
This basic pattern of view navigation is roughly found in UITabBarController and often in views controlled by UISegmentedControls.
Hopefully this helps!
If you are developing a game in Cocos-2d,the transitions between scene can be done like this:
[[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:0.5f scene:[GameOver scene]]];
Here GameOver is a new scene ,to which it goes after transition effect.
There are many other transitions in cocos-2d for going from one scene to another i.e
0. CCTransitionCrossFade
1. CCTransitionFade
2. CCTransitionFadeBL
3. CCTransitionFadeDown
4. CCTransitionFadeTR
5. CCTransitionFadeUp
6. CCTransitionFlipAngular
7. CCTransitionFlipX
8. CCTransitionFlipY
9. CCTransitionJumpZoom
10. CCTransitionMoveInB
11. CCTransitionMoveInL
12. CCTransitionMoveInT
13. CCTransitionPageTurn
14. CCTransitionRadialCCW
15. CCTransitionRotoZoom
16. CCTransitionShrinkGrow
17. CCTransitionSlideInB
18. CCTransitionSlideInL
19. CCTransitionSlideInR
20. CCTransitionSlideInT
21. CCTransitionSplitCols
22. CCTransitionSplitRows
23. CCTransitionTurnOffTiles
24. CCTransitionZoomFlipAngular
25. CCTransitionZoomFlipX
26. CCTransitionZoomFlipY
Thanks

Resources