Got an iOS 5 storyboard question. First app I'm building with Storyboards and i like using them, but i can not for the life of me figure out how to load a view from a UIActionSheet button. I have the UIActionSheet running just fine and it loads a UIAddressBook picker, but I want to have it switch to a new storyboard view controller.
Any ideas?
Here's some of the code:
// Specify what to do when a user selects a button from the personSelectQuery
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
[self showAddressPicker];//This works just fine to show the address book
} else if (buttonIndex == 1){
[self showAddPersonView];//This is the custom storyboard view i want to load
}
}
Look at the [UIStoryboard instantiateViewControllerWithIdentifier:] method. You can set an identifier for specific ViewController in attribute inspector of IB. You call above method using this identifier as a parameter and iOS instantiates the ViewController from storyboard. The rest is the same as other ViewControllers without Storyboard.
Related
I am working on UISplitview base project.I have one problem regarding UISplitview.I want to hide masterDetailview (LeftSide view) in portrait mode form other UIview controller class .How can i do that ?
I declared UISplitviewcontroller in Appdelegate and create separate detail view class.
Try this link http://www.raywenderlich.com/1040/ipad-for-iphone-developers-101-uisplitview-tutorial you will get your answer.
or try this
- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}
this for remove masterViewController
I have a very simple application that has only 2 view controllers. The initial root controller has two UIButtons on it, and they both transition to the 2nd view controller via Storyboard. The information that is loaded on the 2nd view controller is determined by a buttonPressed IBAction that is linked to both the initial view controller. The problem I am having is that once I tap one of the two buttons, I get the 2nd view controller loading up blank. From debugging, I notice that the buttonPressed function is called after the 2nd view is loaded. How can I make it so that the buttonPressed function is called BEFORE the 2nd view controller is loaded blank?
Hardly any code involved, I have both UIButtons tagged 1 and 2, and the button press function loads two text files depending on the sender tag equaling 1 or 2. Everything is linked up in Storyboard. Any suggestions?
*buttonPressed function:
if([sender tag] == 1)
count = 1;
else
count = 2;
The count determines the file to be loaded.
*In Storyboard, I have just 2 view controllers, (No navigation or any of that) and two UIButtons on the initial view and a text view on the second to display text. The UIButtons are connected to buttonPressed and to the 2nd view controller segue.
Don't bother with a IBAction for button pressed. Have the buttons segue to the new controller and use prepareForSegue:sender: to figure out which button was tapped (the sender).
You can then get a reference to your controller that's about to appear with something like...
SecondController *next = (SecondController *)[segue destinationViewController];
...and tell it which file to load, which it can do in viewDidLoad:.
This sounds like a case for prepareForSegue!
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"First Button Segue Identifier"])
{
ViewController *theViewController = segue.destinationViewController;
theViewController.textProperty = self.firstButtonText;
}
else if ([[segue identifier] isEqualToString:#"Second Button Segue Identifier"])
{
ViewController *theViewController = segue.destinationViewController;
theViewController.textProperty = self.secondButtonText;
}
}
There you go, it is pretty generic because I didn't know your variable names or what text you are using. Similarly, if the segues don't have seperate identifiers, you can use the sender to determine which button is being pressed.
Good luck!
I have a segmented control in the header of a navigation controller, I want to add an object to a table view controller thats also in this navigation controller.
Heres where my question comes in:
How do I segue from one [+] UIButton to 1 of 2 views, a different add view for each segmented control option. You can only hook up one segue from a UIBarButtonItem in the storyboard, but I wasn't sure If i just hook one up and then change the code somewhere or if i have to build separate xib files (which I'm not familiar with, I'm new to iPhone dev) or how this would work!
Please help!
You make what I call "generic" segues that are not associated with an action/trigger. See my answer here: How to make and use generic segue
Make 2 of these segues, then in your IBAction method for your segmentedControl call performSegueWithIdentifier:. For example:
- (IBAction)segmentCtrlChanged:(id)sender {
UISegmentedControl *seg = sender;
if (seg.selectedSegmentIndex == 0)
[self performSegueWithIdentifier:#"segue1" sender:self];
else if (seg.selectedSegmentIndex == 1)
[self performSegueWithIdentifier:#"segue2" sender:self];
}
You only need one segue in your storyboard.
in you viewcontroller, add the
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
method, and use switch to decide which segment is being selected.
e.g.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
switch (self.segmentedButton.selectedSegmentIndex)
{
case 0:
{
UIView1 *view1 = (UIView1 *)segue.destinationViewController;
// do other customization if needed
break;
}
case 1:
{
UIView2 *view2 = (UIView2 *)segue.destinationViewController;
// do other customization if needed
break;
}
default:
break;
}
}
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIStoryboardSegue_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIStoryboardSegue
I want screen 1 to be shown when tabbaritem 1 is clicked and if I change some settings, i go to different view, , when I click the tabbaritem 1 again I want to show screen 2.
I have a UITabbar based app and the MainWindow.xib has different tabs loaded before with views.
How do I change it programmatically?
Please help
just put the code for the views to be created in the method viewWillAppear instead of viewDidLoad. This is being called each time go go back to your tab 1
Implement below method in your App Delegate
- (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
UINavigationController *nc;
nc = viewController;
if(controller.selectedIndex == 3){
[[nc.viewControllers objectAtIndex:0] replaceSubView];
}
}
Here,
if(controller.selectedIndex == 3)
3 = your viewcontroller index in which you want to change subview.
And "replaceSubView"
is your method in view controller in which you want to change subview.
Let me know in case of any difficulty.
Cheers.
Turn MainWindow or AppDelegate into UITabBarDelegate, than use
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
to caught tab selections. When tab you need is selected, use image property of UITabBarItem to set image you like.
I want to hide an image when the tabBar button is pressed.I have
self.tabBarController.delegate = self;
in my app delegate and the code below is located in my view controller's .m file . but it doesn't work . Can anyone help pls ?
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if (viewController.tabBarController == nil)
{
img.hidden = YES;
NSLog(#"Tab Bar Button");
}
}
Do you know that
In versions of iOS prior to version
3.0, this method is called only when the selected view controller actually
changes. In other words, it is not
called when the same view controller
is selected.
In addition to this, make sure you are hiding the imageView that contains the image.
UPDATE
Get the tabBarController instance in the view controller and make its delegate the view controller. Then you can call this method in the view controller.
give name for the tabbarcontroller and then set the delegate for that.If my suggestion not useful,then ask me freely