UIViewController Is Not Working - ios

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.

Related

Shared iAd on Tabbed Application

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];

Getting Started with MMDrawerController

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:.

Programmatically Selecting a TabBarController View?

In order to get my custom menu up and running, I've ended up using a UITabBarController and need to change the view displayed programmatically, vs the standard tabbed menu on screen.
Everything is working as expected except on thing. I am attempting to use:
[self setSelectedIndex:index];
This code is inside my UITabBarController subclass in a custom delegate method. (This is so I can programmatically adjust the view when interacting with my menu). However, while this code is called, it doesn't do anything?
Does it HAVE to be called from one of the tabbed views? I was hoping to run it from inside the TabBarController to avoid repeating the code in each tabbed sub controller.
UPDATE:
Just found that using [self setSelectedIndex:index]; works fine in viewDidLoad. But when it is called inside the delegate method, it doesn't change view. It is using the right index number and getting called, but not doing anything from that method.
Also, it seems the tab controller is a different object when I log self in viewDidLoad vs my delegate method. So why would I be loosing the reference to the original controller?
It's just a UITabBarController in a container in another view controller.
Delegate Code:
#Interface
#protocol SLMenuDelegate <NSObject>
#required -(void)menuDidChangeViewToIndex:(NSInteger)index;
#end
#property (nonatomic, assign) id<SLMenuDelegate>menuDelegate;
#Implementation
#synthesize menuDelegate;
self.menuDelegate = [self.storyboard instantiateViewControllerWithIdentifier:#"TabBarViewController"];
[menuDelegate menuDidChangeViewToIndex:[self.menuItemButtons indexOfObject:sender]];
UITabBarController
-(void)menuDidChangeViewToIndex:(NSInteger)index
{
[self setSelectedIndex:index];
}
Setting breakpoints and running NSLogs and there is no question that the method gets called and all code runs.
Try using delayed performance:
dispatch_async(dispatch_get_main_queue(), ^{
[self setSelectedIndex:index];
});
I didn't manage to find a solution to the exact issue, but I found an equally good way of resolving my issue simply.
I stopped using a delegate to send my button tap message and change the view. Instead I did the following:
SLTabBarViewController *tabBar = [self.childViewControllers objectAtIndex:0];
[tabBar setSelectedIndex:[self.menuItemButtons indexOfObject:sender]];
This gets the embedded tab bar controller and I simply directly change the view from the original view controller from which the button tap comes from.
It may not be an intelligent solution, but its a simple and functional one which doesn't create any problems.

UITabBarController/UINavigationController rotation issues

My problem is the following: I want to only allow Portrait orientation on all my ViewControllers except 1 ViewController which is supposed to allow both Portrait and landscapeLeft/Right. I have now spent almost 2 days into how to set orientation in IOS for different slides/ViewControllers. After some searching I found this thread here at stack: UITabBarController Rotation Issues in ios 6
I followed Kunani's example in that thread which I will post here to save all readers some time:
Zack, I ran into this same issue. It's because you have your viewController embedded inside of a TabBar Controller or UINavigationController and the calls to these methods are happening inside those instead of your normal View (Changed in iOS6). I ran into this issue because I was presenting a viewController embedded inside a UINavigationController on all my modal views that had Navigation to different views (Signup Process, Login, etc). My simple fix was to create a CATEGORY for UINavigationController that includes these two methods. I have shouldAutorotate returning NO anyway because I don't want my modal views rotating. Your fix may be this simple, give it a try. Hope it helps. I created a category and named it autoRotate and selected theUINavigationController option. The M+H file are below.
#import "UINavigationController+autoRotate.h"
#implementation UINavigationController (autoRotate)
-(BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#end
... and the category .h:
#import <UIKit/UIKit.h>
#interface UINavigationController (autoRotate)
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
#end
I did what he said and tried to set category for my UITabBarController which worked, all classes connected to the tabBar now only allows orientationPortrait. But if you look at the following Picture
(screenshot from my project) there is a class in the middle of the StoryBoard called ShowTaskView. This class is connected to most classes (which are directly connected to the UITabBarController) via a UINavigationController. Even if I set UITabBarController to only allow Portrait also ShowTaskView seems to get affected by that rule and I can not make it to rotate. The scheme in my project can also be described as this:
TabBarController ----> UINavigationController -------> class X ----------> class ShowTaskView
What can I do from here if I want my classes connected to tabBarController only to allow orientationPortrait and the rest of the classes allow both portrait and landscape based on how my project is built? I am very frustrated at this issue since it is so damn hard to solve :/
Regards
please refer to my answer in similar thread: Navigation controller stack in landscape mode, but modally presented view controller view always in portrait frame size
iOS6 controls rotation by the navigation stacks, so wrap your rotatable view into separate navigation controller to be able to control it there.

IOS blank start screen

I created a controller called Login with the xib file. I'm wanna make it the start screen. so in my app delegate,
H file:
UIWindow *login;
#property (nonatomic, retain) IBOutlet UIWindow *login;
M file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.login makeKeyAndVisible];
return YES;
}
am I missing anything like linking to interface builder? am getting a blank screen
I think you need to create a UIViewController subclass together with your login nib file and then alloc and init this view controller so that you can then make the UIViewController's view the main view.
Even better would probably be the use of storyboard, where you can easily set the initial view controller all on your storyboard.
There is a good Tutorial about iOS Storyboards. I personally find the use of storyboards very convenient. In this SO question I listed some of the pros and cons of storyboards (IMHO):
Does storyboard eliminate the need for .nib

Resources