I am new to iPhone development. I am working on a project having split view controllers. What I am doing is as follows
[self.splitViewController removeFromParentViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *detailViewNav=[[UINavigationController alloc]initWithRootViewController:SampleViewController];
self.nextSplitControler=[[UISplitViewController alloc]init];
self.nextSplitControler.viewControllers=[NSArray arrayWithObjects:masterNavigationController,detailViewNav, nil];
self.nextSplitControler.delegate=SampleViewController;
self.window.rootViewController=self.nextSplitControler;
[self.window makeKeyAndVisible];
It works fine on iOS 5.0 . But on iOS 4.3 it throws an error as
-[UISplitViewController removeFromParentViewController]: unrecognized selector sent to instance.
Can any one help me with this issue? I am banging my head.
Don't bang your head; check the docs. :)
- (void)removeFromParentViewController
Availability
Available in iOS 5.0 and later.
Related
I need to set the view controller of the home screen as the the root of the navigation controller, no matter how the user reaches it (push/show or custom segue)
The following code put in the viewDidLoad of a view controller seems to have no effect with iOS 7:
[self.navigationController setViewControllers:#[self]];
The navigation stack does not change at all.
Have you ever experienced any similar issue?
Thanks,
DAN
Call your UIViewController method from app delegate like this..try it out.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController* pp = [[ViewController alloc] init];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:pp];
self.window.rootViewController = nav; or [self.window setrootviewcontroller=nav];
[self.window addSubview:[nav view]];
[self.window makeKeyAndVisible];
Only one line to make your current viewController as rootviewcontroller
[[[UIApplication sharedApplication] delegate] window].rootViewController = self;
Create global reference of navigation controller in App Delegate and then with the reference of appDelegate you can change you rootView controller anywhere just type below code :
[appDelegate.navigaitonController initWithRootViewController:viewController];
Note: Here viewController is new viewcontroller reference which you want to set as root of navigation controller .
I created a project on xcode 6.0 and I've been running the project on ios8 simulator however when I tried run it on iphone5s ios7.1 simulator the UIWindow frame became to 320x480...
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
above is how I create UIwindow
What shall I do?
You must add correct size iphone/ipad default images, your problem will be solved. , see this link for further details Launch images screen size for iphone
I want to make my iOS application support iPhone 5. So I created a separate xib set for iPhone 5 size. Then I load each xib by checking the screen height.
This is the splash screen loading code inside the AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1;
if ([UIScreen mainScreen].bounds.size.height==480) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen" bundle:nil];
}
if ([UIScreen mainScreen].bounds.size.height==568) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen5" bundle:nil];
}
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
But when I change the simulator into Retina 4-inch, my code doesn't get the emulator size. It always executes the 480 if condition.
But other apps I created like this are working properly.
What is the reason for this?
I'm having the exact same problem right now (at the worst moment, of course....).
It did work properly for several weeks, and for a unknown reason, the simulator suddenly considers the 4in simulated device as a 3.5in screen.
cleaning, reset, reboot : same situation...
EDIT : ok, problem solved. T'was because of a missing Default image in the -568#2x format. I knew that was a condition to make the system work, but xcode had apparently decided to get rid off the one I chose. oh well...
I seem to be having an issue since I started using iOS 6, which doesn't appear when using iOS 5. At first, I thought it might just be a simulator bug, but since testing it on my iPhone 5 today, I can see that it's not just in the simulator.
I'm creating everything programmatically — I seem to prefer doing it that way (I assume it's because of my HTML/CSS background!) — but I'm still reasonably new to Objective-C, and I couldn't find a full example of how to set up a navigation controller/table view programmatically, so I put it together from the nuggets of information I could find, and therefore, I could be doing something fundamentally wrong. However, it's worked (and still works) perfectly on iOS 5.
The problem is that I have a black bar between the navigation bar and the table view, but the strange thing is that if I push a view and go back to that original view, the bar disappears, and doesn't reappear until I completely restart the app.
The following image is of the app at launch (1), as I'm pushing a view in (2), and the initial view, after I've gone back to it (3):
This is what I have as my code:
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootController = [[RootViewController alloc] init];
self.window.rootViewController = rootController;
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
NSLog(#"Window frame: %#", NSStringFromCGRect(self.window.frame));
return YES;
}
RootViewController.m
- (void)loadView
{
self.title = #"Title";
self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.view = self.tableView;
NSLog(#"tableView frame: %#", NSStringFromCGRect(self.tableView.frame));
UIBarButtonItem *newViewButton = [[UIBarButtonItem alloc] initWithTitle:#"New View"
style:UIBarButtonItemStylePlain
target:self
action:#selector(newViewButtonTapped:)];
[self.navigationItem setRightBarButtonItem:newViewButton animated:NO];
}
I added the NSLogs to see if they showed anything that might help me. The output is:
tableView frame: {{0, 0}, {320, 480}}
Window frame: {{0, 0}, {320, 480}}
Can anyone give me any ideas about what I'm doing wrong? It seems is having a similar/the same problem (Black bar overtop navigation bar — in the comments), but I haven't found an answer.
Thanks, in advance!
You're adding the RootViewController to the window twice, once by setting UIWindow.rootViewController (which internally does [window addSubview:rootViewController.view]) and again by adding it as a subview of the navigation controller.
You should be doing this:
RootViewController *rootController = [[RootViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigationController;
As a rule of thumb, never add a view directly to the window unless you know that you actually want to.
my app is built with a UITabController and works as imagined. However, for one of the views within my UITabBar, I would like to add a table that when something is pressed will take me somewhere. And I would like to do this just within this one view.
I know how to build a table and populate and get it to go somewhere but my issue is I can't seem to get my app to run with the table. I feel like my connections are off and specifically with appDelegates. I already had two appDelegate files (.h & .m) before adding the UINavigationController so from here I really don't know what to do. I took apple's simpleTableView tutorial files and copied them over to mine. It still crashes. I even copied there appDelegate files (so now I have 4) but the same deal. This is the error I am getting but in general I just feel lost with the delegates and connections.
2011-12-12 12:08:50.302 TabbedCalculation[68713:207] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
* Call stack at first throw:
If anyone can offer any help, it would be much appreciated.
Thanks!
P.S. I have changed within the mainWindow.xib of the UITabController to point one of the tabs to the appropriate class and xib file so that is not the issue but I have noticed that many tutorials want within the app delegate this line to the navController:
[window addSubview:[navigationController view]];
but I have already set it to the tabBarController.
Your app can only use one set of app delegate files. So copying over a the example's app delegate files does not mean they are being utilized. You need a navigation controller inside the specific tab you want to contain the tableview. Here is an example of a navigation controller inside a tab bar controller, by modifying didFinishLaunchingWithOptions in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AllTaskViewController *view1 = [[AllTaskViewController alloc] initWithNibName:#"AllTaskView" bundle:nil];
view1.title = #"All Tasks";
TodayTaskViewController *view2 = [[TodayTaskViewController alloc] initWithNibName:#"TodayTaskView" bundle:nil];
view2.title = #"Today's Tasks";
HistoryViewController *view3 = [[HistoryViewController alloc] initWithNibName:#"HistoryView" bundle:nil];
view3.title = #"History";
SettingsTableViewController *view4 = [[SettingsTableViewController alloc] initWithNibName:#"SettingsTableView" bundle:nil];
view4.title = #"Settings";
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:view1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:view2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:view3];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:view4];
[view1 release];
[view2 release];
[view3 release];
[view4 release];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
[nav1 release];
[nav2 release];
[nav3 release];
[nav4 release];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Note: All 4 view controllers have an individual navigation controller, and each one is a custom view controller. I used nibs here, but you don't necessarily have to. And the app itself has no main window, you would need to modify this slightly if you are using a main window for the app.