i am trying to develop mac application(cocoa app).i have successfully used tabbar in iphone app. but in developing mac application ,how to use tabbar?
As we use tabbar for iphone application,i want to implement same kind of functionality for Mac App(cocoa app).
any idea?how its possible?
I presume you are talking about an NSTabView when you refer to "tabbar" or "Tababr"...
You do not need to write your whole app in one AppDelegate.
You can add your AppDelegate as a delegate of your NSTabView and then implement tabView:didSelectTabViewItem:. This allows you to intercept requests by the user for different tabs. Just create an outlet for your tab view and set the delegate:
[[self tabView] setDelegate: self]
Based on the requested tab you can then create the view controller associated with that tab and load the NSView into the selected tab. Something like:
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem {
MyViewController aController = [[MyViewController alloc]
initWithNibName: #"MyView" bundle: [NSBundle mainBundle]];
[tabviewItem setView: [aController view]];
}
I'm not sure whether you need to add NSTabViewDelegate as a protocol to your AppDelegate but if Xcode flags a warning you'll notice:
#interface MyAppDelegate : NSApplicationDelegate <NSTabViewDelegate>
Hope this helps. Otherwise you need to elaborate on your requirements.
Related
I need to present the classic walkthrough when the Application get launched the first time but, with the implementation that I have in mind, I end up with a structure that keeps the walkthrough as first controller of the hierarchy... and I don't like that. Here is a description of my implementation:
1) In the didFinishLaunchingWithOption I check UsereDefault to catch the first launch
2) If is the first launch I substitute the rootViewController of the window with the walkthrough
3) When the walkthrough is finished I present the first view controller of the App
The problem is with point 3. Presenting the controller from the walkthrough I end up with the whole application presente as modal of the walkthrough... what I want is to completely substitute the walkthrough with the standard first view controller.
Could you suggest a good pattern to show/dismiss a walkthrough?
When you finish Walk-through, replace the rootViewController of your window.
FirstViewController *firstVC = [[FirstViewController alloc] init];
yourAppDelegate.window.rootViewController = firstVC;
Or if you are using storyboard:
FirstViewController *firstVC = (FirstViewController *)[[UIStoryboard storyboardWithName:#"YourStoryboardName" bundle: nil] instantiateViewControllerWithIdentifier:#"YourFirstVCId"];
yourAppDelegate.window.rootViewController = firstVC;
Another option is Show the Walkthrough as modal on top of FirstViewController if it's first time.
Have a look at this library to implement your walkthrough https://github.com/ruipfcosta/SwiftyWalkthrough.
I have added a Storyboard file to an app that initially had none. For some reason, I could not get my custom UIViewController to display correctly until I added this into didFinishLaunchingWithOptions:
ActivityViewController *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:#"ActivityViewController"];
Why do I need to force the use of my storyboard like this? The iOS template projects (Single View, Master-Detail etc) doesn't need this.
Checklist:
Xcode Project Summary→Main Storyboard is set correctly to "MainStoryboard".
Interface Builder→Identity Inspector→Class is correctly set to "ActivityViewController".
Interface Builder→Identity Inspector→Storyboard ID is also set to "ActivityViewController", but this is only because it's needed by instantiateViewControllerWithIdentifier.
You do not need to call instantiateViewControllerWithIdentifier if you set Is Initial View Controller on your "ActivetyViewController" in the storyboard. The initial view controller will have an arrow pointing at it.
I am developing an application that loads a web page (using UIWebView) using Storyboard (I do know nothing about previous xib neither). I have already created a view controller for that UIWebView and everything works fine. The thing is: since previous versions of iOS don't allow to upload files, I need to make a new view (scene I thought it is called) that allows the user to pick and post a picture. I am able to develop both views separately and they work as expected but now I need to connect them based on event triggered when user wants to post a picture to the server. Using shouldStartLoadWithRequest I can catch that action, then I need to redirect to new view (which contains image picker and a button in order to upload the selected image) if iOS version is below 6.0 but I am really lost when it comes to load the new controller to show that view. Using buttons it is trivial but I don't know how to called inside the code. So far, I have a view controller linked to that scene and I have tried these ways:
WritePostViewController *postViewController = [[WritePostViewController alloc] init];
[self.navigationController pushViewController:postViewController animated:YES];
And even calling the storybard:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
[sb instantiateInitialViewController];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"WritePostView"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
The first approach does nothing and second one shows this error log:
* WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: Storyboard () doesn't contain a view controller with identifier 'WritePostView'*
I have been browsing and reading a lot but nothing solves my problem. For sure this a problem with my not-so-large knowledge about iOS but I am really stuck. I will thank any help.
By the way, I need to come back after posting the file but I could imagine it is the same way opposite direction, right?
If your code is inside a view controller (which it seems to be), you can get the current storyboard with self.storyboard. You also don't need instantiateInitialViewController because, if all your UI is coming from the same storyboard, it has already gone through the loading of the initial controller.
As for the actual error, it's complaining that #"WritePostView" isn't a recognized name for any view controller in the storyboard. Note that what it looks for here is not the class name for the controller but the Storyboard ID for the controller. (Which makes sense since you could have different "scenes" with the same type of controllers.)
Ok, it seems is solved. I just have added a segue between scenes
and then I just need to add this one:
[self performSegueWithIdentifier:#"writePostViewSegue" sender:self];
and it works!. Anyway, I am not sure if it is the way to do it, so if someone knows better, please let me know.
Cheers
I am in the process of converting an iPhone app to a universal app.
I've changed all the xCode settings and added a new MainWindow-iPad.xib
I've hooked all the interface builder references up (e.g. MainWindow-iPad to the appropriate iPad class viewController, window etc)
I've added a new iPad class for the opening view controller and declared it in my AppDelegate.h file, and synthesized them in my AppDelegate.m file:
UIWindow *window;
UIWindow *windowiPad;
AppViewController *viewController;
AppViewControlleriPad *viewControlleriPad;
in the app delegate I check for which device I am running and load the appropriate class:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Override point for customization after application launch.
navController = [[UINavigationController alloc] initWithRootViewController:viewControlleriPad];
// Add the view controller's view to the window and display.
[windowiPad addSubview:navController.view];
[windowiPad makeKeyAndVisible];
[navController setNavigationBarHidden:YES animated:NO];
} else {
//I am an iPhone!
// Override point for customization after application launch.
navController = [[UINavigationController alloc] initWithRootViewController:viewController];
// Add the view controller's view to the window and display.
[window addSubview:navController.view];
[window makeKeyAndVisible];
[navController setNavigationBarHidden:YES animated:NO];
}
And everything seems to work fine - except it still loads the iPhone nib/xib file AppViewController.xib instead of AppViewControlleriPad.xib. You're welcome to ask for more information but I can't figure out how to get it to load the AppViewControlleriPad.xib when running an iPad rather than the iPhone/original xib file.
I thought, perhaps naively, that if the xib file has the same name as the class of the view controller then the ViewController would use that as its xib.
How can I fix it so that the correct xib is loaded for the correct device?
You have a spelling mistake - correct sufix for iPad resources is "~ipad" instead of "-iPad". With "~ipad" your resources will be loaded automatically depending to device.
And you probably don't need another UIWindow for your iPad controllers. You can use the same window at app starting point. Good practice is also to have one view controller (inside you can perform some special things for different devices) and two nibs (one "normal" and the second one with "~ipad" sufix). In rare cases if whole controller behavior is completely different you may want to use two view controllers.
It may be due to the reason that you didn't connect iPad's view controller to files owner in IB.
I am just starting with iPad App development. I want to use splitViewController in my app. I want to use different viewControllers. These will be loaded on rightHandView of an ipad when user selects appropriate on tableviewcontroller present on left hand.
I am using iOS SDK 5.0 without storyboard. I have seen apple's example of multipleDetailView and tried to follow similar procedure but its not working with iOS 5.0 sdk and Xcode4.2, I can not able to access MainWindow.Xib in my project as there is not one when you create project with XCode4.2 and master detail template.
Can anyone tell me how to approach this problem or direct me to appropriate resources ?
Regards,
Sumit
It seems that compared to previous versions, XCode 4.2 generates the relevant code in the "AppDelegate.m" instead of somewhere in the .xib file. I'm not sure about how to work with a MainWindow.xib here, but you could easily push other view controllers in the detail view navigation controller programmatically:
Use the following code for example on a button touch up action:
- (IBAction)buttonClick:(id)sender {
MySecondViewController *vc = [[MySecondViewController alloc] initWithNibName:#"MySecondViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:TRUE];
}
To dismiss the top controller and get back you can use either
[self.navigationController popViewControllerAnimated:TRUE];
in the new top-of-the-stack controller (here MySecondViewController) or just the Back button in the navigation bar.