I am following a very easy tutorial "My first iOS app" by apple on xcode 4.2 sdkiOS5.
According to the tutorial, I am supposed to ctrl-drag a button, a text field and a label into the implementation file. myviewcontroller.m (not the .h)
According to this tutorial and its images. in this myviewcontroller.m I am supposed to see
#import "HelloWorldViewController.h"
#interface HelloWorldViewController{}
#end
#implementation HelloWorldViewController
...
and supposed to drop from the view between the #interface and the #end.
The thing is that, from what I see in xcode, the #interface thing is not in myviewcontroller.m but in myviewcontroller.h
in myviewcontroller.m I can only see this:
#import "HelloWorldViewController.h"
#implementation HelloWorldViewController
- (void)didReceiveMemoryWarning
{....
When I try to drag buttons and text fields in myviewcontroller.m the popover doesn't allow me to change into "outlet", it's fixed on "action".
On the other hand, if I try to do the same in myviewcontroller.h, I can do whatever I want, the declaration corresponds to the images shown in the tutorial (that I drop between #interface ...
(here)
#end )
but when I run the simulator, the screen stays black. Obviously, there is something wrong.
If anyone can help out a little, that would be awesome.
Cheers
Related
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.
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 <>)
The weirdest thing is happening in Xcode. I had a View Controller file, called SettingsViewController. From SettingsViewController, I am trying to push GameViewController. When I was making this file, I mistakenly named it ViewViewController instead of GameViewController (it was late :D). I set the class of the files' respective views in the identity tab in the storyboard file. Later, I tried to change the name of the file ViewViewController to GameViewController by right-clicking on it in the left column and clicking rename. I went into the storyboard file, and changed the class of the game view. Now, I can import the GameViewController file into the SettingsViewController file by saying
#import GameViewController.h
But the following line gives an error:
GameViewController *gvc = [[GameViewController alloc] init];
The error says unknown type name GameViewController: Did you mean ViewViewController?
Am I missing a change that needs to be made? All I did was change the name of the file and change the class in the storyboard.
As I was about to post this question, I realized the answer. I had to go into GameViewController.h and change the line
#interface ViewViewController : UIViewController
to
#interface GameViewController : UIViewController
Then, in GameViewController.m, I had to change:
#interface ViewViewController ()
to
#interface GameViewController ()
and change
#implementation ViewViewController
to
#implementation GameViewController
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.
I'm trying to get MMDrawerController to work, and I'm having trouble.
Here's is how much app is structured in my storyboard:
Here's how I'm attempting to initialize it from within my root view controller:
//LCViewController.m
#import "LCViewController.h"
#import "MMDrawerController.h"
#interface LCViewController ()
#property (nonatomic,strong) MMDrawerController * drawerController;
#end
#implementation LCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"centerNav"]
leftDrawerViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"menu"]
rightDrawerViewController:nil];
}
...
#end
When I build my app, all I see is my root view controller. Is there something else I'm supposed to do to implement the drawer functionality?
I created a demo project to show how I'm trying to set up my app. You can download the Xcode workspace here. Thanks in advance for your help!
I'm using Xcode 5 and iOS 7
EDIT: Sorry I initially misunderstood your app structure. The MMDrawerController should be the root view controller of your application. You should move this code from viewDidLoad to application:didFinishLaunchingWithOptions:. Add an MMDrawerController property to your app delegate, init the drawer controller with your appropriate views, and set the drawer controller to the rootViewController on your UIWindow. Do this along with setting the gesture modes as I described below and the drawer should work.
To get the basic open/closing gestures, set this properties on your drawer controller:
self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
self.drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
These properties default to MMOpenDrawerGestureModeNone which is why you couldn't make anything slide. You can have a look at the MMOpenDrawerGestureMode and MMCloseDrawerGestureMode bitmasks to get finer grained settings if you desire.
You can also create UI controls that toggle the drawer by calling toggleDrawerSide:
animated:
completion:.