How to display only UIview IOS7? - ios

Hi in storyboard i have added a new view controller object inside the view controller i have a small registration from with only two fields example like name and phone number. In that when user open the application i want display only the newly added UIview.
But the problem is uiview is showing with the storyboard please tell me how to display only the uiview. Is that possible to do ? possible means please tell how to make it done. I'm navigating the view from my app-delegate.
App delegate code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
buttonpoliticalViewController *ringingVC = [mainstoryboard instantiateViewControllerWithIdentifier:#"Upcv"];
[self.window setRootViewController: ringingVC];
return YES;
}
In above code i have used the storyboard id to view the view controller please tell how to display only uiview.
Thanks.

Related

UIStoryboard Change Tab Bar Button Text

I am writing program with MainStoryBoard like this. I have UITabBarController with 5 tabs. In viewdidload of each uiviewcontroller, I set like this. But, it will only do if I go to that page. So, I am planning to do in my AppDelegate for all tabs. How shall I do programatically? I can set text in UIStoryBoard but I need to set programmatically.
self.title = #"Some title";
For this you should get the storyboard instance first. And then get tabbar from story board. Do this in the following method of AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UITabBarController *tabBar = [storyBoard instantiateInitialViewController] ;
NSLog(#"%#",tabBar.viewControllers);
// You will get list of your viewcontrollers added to tabbar .Get the instances of those view controllers and set title to them here.
return YES;
}

Pushing ViewController from app delegate

I am using a storyboard in Xcode 5, which appears as so:
My requirement is to push a ViewController (VIEW1 or VIEW2) into view from the app delegate. Essentially it should not matter what view is presently on the screen -- I would just like to make a ViewController appear when the app delegate picks up an external event.
In order to try and achieve this, I have property references to both the TabBarCtrl-Products and NavCtrl-ProductA in my app delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_tabBarProducts = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"sidTabBarProducts"];
NSArray *tabvcs = _tabBarProducts.viewControllers;
for (id controller in tabvcs){
if ([controller isKindOfClass:[VCNavControl_ProductA class]]) {
_navControllerProductA = controller;
break;
}
}
return YES;
}
The app delegate method to push VIEW2 is:
-(void)showVCVIEW2
{
VC_V2 *targetvc = nil;
targetvc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"sidView2"];
[[AppDelegate sharedInstance].navControllerProductA pushViewController:targetvc animated:NO];
}
This works OK when VIEW1 is showing at the time showVCVIEW2 is called, however it does not work when ViewCtrl-ProductB is showing. I can see that the new instance of targetvc has been added to the AppDelegate _navControllerProductA's stack, however it does not display.
(Regarding the setting of the the app delegate's rootViewController, I set this to _tabBarProducts after the VC-Splash and VC-Setup ViewCtrls have finished).
I would appreciate very much if anyone can give me an idea on how to achieve this. I suspect my problems stem from having a NavCtrl in a TabBarCtrl, but I do not know a way around this.
Your problem is that the navigation controller you are pushing on is not in the view hierarchy.
You instead could try setting the tabBarController's selected index like this:
[self.tabBarController setSelectedIndex:1];

Why am I unable to change my initial view controller programmatically in my AppDelegate?

I'm following the advice of this question in order to define my initial view controller at runtime, instead of always being the same based off of the Storyboard property.
This is my didFinishLaunching method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *compactNavigationController = [mainStoryboard instantiateViewControllerWithIdentifier:#"CompactNavigationController"];
self.window.rootViewController = compactNavigationController;
[self.window makeKeyAndVisible];
CompactPostsViewController *controller = (CompactPostsViewController *)compactNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
And I've unchecked "Is Initial View Controller" in my Storyboard, and I've removed "Main" from the default Storyboard in my app's info.
But when I launch the app I get a completely black screen. What am I doing wrong?
Your window is nil because you never created it. You need to add this line,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
The window is created for you when you have the "Main storyboard base name" entry in your info.plist, but if you remove that, then you have to create the window yourself.
check your linkings in your storyboard(by right click on the tableview controller).This happens mostly when you not linked your tableview controller properly.

Initiating a view properly with navigation bar

My app consists of a navigation controller and view controllers. Some parts of my UI is done on storyboard and some are initiated from code (in viewDidLoad). My goal is to load childViewController X (consists of a back button, nag bar, label and table) when the app is launched from a push notification "properly" through this method in appDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This might be a simple question to you guys but I've asked several questions the pass few days (you can look at my questions history). After trying several methods, my app either:
crashes
loads without navigation bar
loads with navigation bar but no label (back button does not work)
loads with navigation bar but with black screen underneath
Only the tableView is dragged onto storyboard. The navigation bar is inferred but I have code that dictates its back button and title. The rest is all done through code in the .m file.
I know people have asked this question before but none of the methods worked. How can I load this childViewController properly through a push notification?
My code so far:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController* firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
[self.window.rootViewController addChildViewController:firstVC];
[(UINavigationController *)self.window.rootViewController pushViewController:firstVC animated:NO];
self.window.rootViewController.childViewControllers);
}}
Error Code:
'-[SWRevealViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14575f20'
SWRevealViewController is my library for my sidebar menu view controller.
I've also tried this method:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
This loads the correct viewController but without a navigation bar.
It looks like you have your rootViewController set to a custom controller of type SWRevealViewController. If you want to call pushViewController:animated: on rootViewController, it must be a UINavigation controller. Currently you are calling it on a controller that does not respond to that message.
In your Storyboard make sure you drag a UINavigationController onto the canvas and move the root-view-controller arrow in InterfaceBuilder to point to it. Then load whatever ViewController you want into the navigationController. (i.e. your code at the top of your question should work).

Issue with storyboard

I want to use storyboard in my old project (which was implemented using xibs) for adding a new features.
I have created storyboard file and added a view controller to it and in Identity inspector I have specified the class name for the view controller.
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:[NSBundle mainBundle]]];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES
}
#end
In the firstviewcontroller when i click on a button it will call the gotoSomeviewController method where it pushes to the eventslistViewController loading from EventsScreen storyboard
#implementation FirstViewController
-(void)gotoSomeviewController
{
EventsListViewController *vc = [[UIStoryboard storyboardWithName:#"EventsScreen" bundle:nil] instantiateInitialViewController];
[controller pushViewController:vc animated:YES];
}
#end
when I'm running application the EventsListViewController is showing a empty screen without the views I have added in storyboard.
Based on the information supplied there should be no reason why you mix NIBs and Storyboard.
I would setup just a storyboard. Remove the app Delegate code and setup the project to load the storyboard for the specific device.
Setup your storyboard to have the initial view controller as a UINavigationController that has the FirstViewController as the root of that.
Then you can simply drag to the SecondViewController from the button and select push as the move option. Then remove your method for gotoviewcontroller. There is no reason why you would have this setup like this...

Resources