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
Related
New to iOS development and I have a tabbed app with 4 tabs. I have an iAd showing on one tab and I don't want to regurgetate the code on every view controller and I know this is not the correct way to implement anyway. I have looked at the Apple code here and I'm struggling to be honest.
https://developer.apple.com/library/ios/samplecode/iAdSuite/Introduction/Intro.html
I have included the BannerViewController.m and BannerViewController.h in my application but I'm not fully sure how to get it to run the ad on each view controller.
Yours confused
JKX
Just grab a reference of UIWindow in any of your ViewController Class
Go to .m of your ViewController
#import "AppDelegate.h"
#interface ViewController ()
{
//make object of AppDelegate
AppDelegate *appDelegate;
}
Now in your viewDidLoad or ViewDidAppear grab the reference of window.
appDelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate.window addSubview:yourBannerView];
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 accidentally assigned the same custom class to two UIViewControllers in Storyboard:
#interface SecondViewController : UIViewController
With this the app ran properly. But when I change the custom class for the second View Controller from FirstViewController to SecondViewController the app crashes when the second View Controller loads. How do I rectify this situation?
More information is definitely needed here. However, one of the things to look for is that if you are using the FirstViewController class in code somewhere (in -prepareForSegue for the presenting UIViewController for instance), you'll need to make sure to change that code so that it's using the proper pointer for the class when referencing the SecondViewController class.
For instance, if you do the following and the destinationViewController is of class SecondViewController, then you will get a crash:
FirstViewController *firstView = (FirstViewController *)[segue destinationViewController];
If you could post the presenting class and the FirstViewController and SecondViewController classes, then we can provide more information.
This is embarrassingly obvious now, but I found the problem arose from a button being linked to an IBAction in the the FirstViewController class. When the app was run it crashed because of the improper link.
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 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