I'm the beginner on iOS development and iPad app programming. Now I'm working in an ipad splitview app in which I have multiple elements. In detail view of others view I added a UISegmentedControl and a UIView, what I want to do is when the Segmentedcontrol is switched the uiview should load and show another .nib file that i have in my project. My project is like this
Master --------------Detail
Picture ----> Picture View
Video ----> Video View.
Website ---> Website View.
Others-------> Others View ((UIsegmentedControl)) ---> another .nib file
So how can i do that? Thank u!!!
To receive action of your UISegmentedControl being clicked you need to do
[mySegmentedControl addTarget: self action: #selector(mySegControlClicked:) forControlEvents: UIControlEventValueChanged] ;
Then implement your mySegControlClicked function like
-(void)mySegControlClicked: (UISegmentedControl*)sender
{
switch([sender selectedSegmentIndex]) {
case 0: //nib loading code ;
break ;
case 1: //nib loading code ;
break ;
}
}
For help with the Nib loading code see load view from a nib
Related
I'm brand new in Xcode and have been able to scoot by with some fairly simple apps thanks to my previous programming experience, the Storyboard in Xcode, and most of all THIS WEBSITE.
One thing I haven't been able to figure out is how to make my app universal? The way I have my app set up is that it looks a lot like the iPhone home screen with pages and app icons. However, when I hit the little "Change to iPhone 5" button, 1) It only changes my FirstViewController and 2)My icons are all out of alignment.
Do I make another storyboard (If so, how?)? Do I make another view controller for each screen resolution? For either of those questions do I program a test to see which device I'm using and for it to choose the correct storyboard or ViewController? My app is currently set to universal, but I still haven't even been able to find the iPad resolution option for view controllers and stuff.
Please be as simplistic as you can. I have only been doing this for an extremely short time. Thanks for all your help both here and around this site!
So In order to get the iPad version working, follow these steps:
First go to your target settings, scroll down to "Deployment Info", and change it from iPhone to Universal
Next you will need to create a new Storyboard file. On the bar at the top go File>New>File and this thing should pop up:
After you have selected iOS>User Interface>Storyboard as shown above, click next and it will ask iPhone or iPad. After selecting iPad, the new file will be ready to map your interface for iPad. However, you need to make sure the app uses it. So go back to your target settings and scroll back down to "Deployment Info" and switch to iPad:
Set the "Main Interface" option to the name of your new storyboard file.
As for preparing for iPhone 5, that part can get a bit annoying. I find that the additional space is too small for any major additions but too large to be ignored easily. How you deal with it will vary greatly depending on what you app does. From what you described, with app icons like the iPhone screen, you will probably want to have an additional row of icons, just like the iOS. To do this, you can either manage it programatically or you may want to have seperate storyboards for iPhone 4 vs iPhone 5. If you want the separate storyboards, this question will have your solution.
To initialize storyboard:
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
UIViewController *initialViewController;
if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:#"iPhone4" bundle:nil];
// Instantiate the initial view controller object from the storyboard
initialViewController = [iPhone35Storyboard instantiateInitialViewController];
}
if (iOSDeviceScreenSize.height == 568)
{
// iPhone 5 and iPod Touch 5th generation: 4 inch screen
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:#"iPhone5" bundle:nil];
initialViewController = [iPhone4Storyboard instantiateInitialViewController];
}
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
return YES;
I have iPad app and it's working great. I'm trying to convert the app to universal app.
1.- In the summary of the app I change it from iPad to Universal
2.-I add it a nib for the iPhone iPhoneView.xib
3.-in my app delagate I add this code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}
else
{
self.viewController=[[ViewController alloc]initWithNibName:#"iPhoneView" bundle:nil];
}
4.-in the iPhone nib I add viewcontroller as custom class
I run the app using the simulator and I got this error:
[UIViewController _loadViewFromNibNamed:bundle:] loaded the "iPhoneView" nib but the view outlet was not set.'
I search for a way to fix and seems like I need the reference outlets to the nib but when I try to drag the connection from the "New Referencing Outlet" on the right side of xcode in the last tab to the nib I can not make the connection or if I try to drag the connection from the view icon to the files owner I can not make the connection neither. Any of you knows what I'm doing wrong?
I'll really appreciate you help.
go to the iPhoneView.xib first set file owner to your view controller
After that click on the file owner(yellow block ) and click on the right most arrow in following picture. set all the connections . This will solve your problem.(Probably i think your view is not set to view outlet)
Note: I've only tested this on the simulator.
I want to add the target-action in code instead of connecting it as an IBAction in Interface Builder.
theButton is on the navigation bar at the top left, created in IB.
Steps:
Declared theButton as an IBOutlet and connected it in IB.
Added this in viewDidLoad:
self.theButton.target = self;
self.theButton.action = #selector(theAction);
I'm testing theAction by this:
- (void)theAction {
NSLog(#"theAction called");
//do some other stuff
}
When I click on theButton in the simulator, nothing happens. I don't see the NSLog statement at all.
What am I missing?
Have you connected the action to the button in interface-builder?
If not you should declare the action in your .h file
-(IBAction)theAction;
Change the name of the action on your .m file
-(IBAction)theAction{
}
And finealy connect the action to the button in interface-builder.
Change your function as below:
-(IBAction)theAction{
NSLog(#"theAction called");
//do some other stuff
}
And if you called like "#selector(theAction:);"
then change function as below:
-(IBAction)theAction:(id)sender{
NSLog(#"theAction called");
//do some other stuff
}
Hope it will be helpful to you.
Let me know in case of any difficulty.
Figured it out. Had to do with my configuration. I'm using a tab bar controller that uses the same view controller for multiple tabs. Each view controller shows different filtered data for some tab items.
Therefore, in such a configuration, you must be sure to connect the IBOutlets for each view controller that's contained by a tab bar item. I only connected one, which is why it wasn't working for some of the tab items.
I'm new to iPhone development, and multiple views (xib or nib) are really confusing me. This is what i'm trying to achieve...
using TabBarControllerAppDelegate
Have 5 different TabBar Items and have created 5 different Views thru the TabBarController
The First View has a UIButton that is a Next button that needs to go to another view called View2.XIB.
I setup a new UIViewController which references the View2 and an IBAction for the switchPage, etc but not able to get it to do anything when clicking on the button.
All of My TabBar buttons work but not able to Navigate to anything outside of the Tabbar
Any help in this regard will be highly appreciated. Anyone have any examples
IBAction switchPageButtonPressed:(id)sender
{
[self.tabbarcontroller.tabBar setSelectedItem:[self.tabbarcontroller.tabBar.items objectAtIndex:1]];
here 1 means ur 2nd tabbar
}
It is difficult to find the problem without the code, but I will assume your action code for the switchPage button is incorrect. You should use code similar to the following:
- IBAction switchPageButtonPressed:(id)sender
{
ViewController2 *view2VC = [[ViewController2 alloc] initWithNibName:#"View2" bundle:nil];
[self presentModalViewController:nview2VC animated:YES];
[view2VC release];
}
If you are confident your method works, then you will want to verify that the action is hooked up correctly. The easiest way to do this is to place a breakpoint on the method and run the app in Debug. When you click the button, the debugger should break on your method, if it doesn't, you will need to check your connections in Interface Builder.
Here is the question
I need to create a panel that apear on the app by clicking on the naviagationItemRightBarButton.
this panel contains labels btn etc...
I tried to do it using a UIPopover but I think that only works for ipad app.
public UIPopoverController CustomPopover;
FilterSortController newpanel = new FilterSortController();
//FilterSortController is UIViewController
CustomPopover = new UIPopoverController(newpanel);
CustomPopover.PresentFromBarButtonItem (this.NavigationItem.RightBarButtonItem , UIPopoverArrowDirection.Any, true);
and after that I overried the ViewDidLoad of the FilterSortController
ContentSizeForViewInPopover = new System.Drawing.SizeF(320,110);
There is no way to create a Popover for iphone using monotouch.
thanks for the help
UIPopoverController is not supported on iPhone. You would have to write your own custom controller and view to get this functionality. There is a open source implementation in ObjC here which you could btouch or port.