i am new to ios development
i have created a slash screen that check internet connection when application load and that is my rootviewcontroller.
i have created a next view using uiviewcontroller in same storyboard name Main_iphone
the storyboard id of viewcontroller is "HomeScreen".
the question is how do i jump on "Homescreen" from "SplashScreen" when internet connection found
I had created the function to jump on next screen-
[self perform:#selector(goToNextView) withObject:nil afterDelay:3];
-(void) goToNextView{
UIStroyboard *iphone=[UIStoryBoardWithName:#"Main_iphone" bundel: nil];
}
Thank you for your time
Try this :
-(void) goToNextView{
[self performSegueWithIdentifier:#"HomeScreen" sender:self];
}
If, you want to set some value use this :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"HomeScreen"])
{
// do here
}
}
Related
If the third nested 'IF' doesn't pass I would like the segue not to run. How can I do that?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showStudentMainPage"]) {
if (![self.studentEmailField.text isEqualToString:#""] && ![self.studentMDCID.text isEqualToString:#""]) {
if ([self.data checkStudentEmail:self.studentEmailField.text checkStudentID:self.studentMDCID.text]) {
StudentMainPageViewController *dest = [segue destinationViewController];
dest.rowInDB = self.rowInDBHere;
}
}
}
}
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender.
This method is only Notifies the view controller that a segue is about to be performed.You can not prevent segue.The default implementation of this method does nothing. Subclasses override this method and use it to configure the new view controller prior to it being displayed.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/performSegueWithIdentifier:sender:
check with this May be it will help
To stop segue and show alert
You should override shouldPerformSegueWithIdentifier on your UIViewController and put your logic there. You cannot cancel a segue inside prepareForSegue. Take a look at the UIViewController reference for more details.
I recently started using storyboard.
I have the main viewcontroller, which by code must call another viewcontroller.
in storyboard, I created a "segue" that goes from the first to the second controller, with the identifier "segueToSignSelection."
in the main viewcontroller, when I need to call up the second viewcontroller, insert this code:
[self performSegueWithIdentifier:#"segueToSignSelection" sender:self];
that calls this method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"segueToSignSelection"])
{
signSelectionViewController = (SignSelectionViewController*)[segue destinationViewController];
[self presentModalViewController:segue.destinationViewController animated:YES];
[segue.destinationViewController test];
}
}
in the second controller, the test method is invoked. But the view does not appear. What could be the problem?
Thanks
How do I call the following method from this IBAction? I want to call the prepareForSegue: method instead of the NSLog(#"clicked");
Here's the IBAction:
- (IBAction) annotationViewClick:(id) sender {
NSLog(#"clicked");
}
Here's the method:
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:#"ShowMoreInfo"]) {
// Get reference to the destination view controller
MoreDetailViewController *mdvc = [segue destinationViewController];
[mdvc setSelectedItemName:[NSString stringWithFormat:#"%#", placeName.text]];
[mdvc setSelectedItemAddress:[NSString stringWithFormat:#"%#", placeFormattedAddress.text]];
[mdvc setSelectedItemWeb:[NSString stringWithFormat:#"%#", placeWebsite.text]];
[mdvc setSelectedItemRating:[NSString stringWithFormat:#"%#", placeRating.text]];
// [mdvc setSelectedItemDistance:[NSString stringWithFormat:#"%#", placeDistance.text]];
}
}
thanks for the help!
prepareForSegue: method calls automatically when you performing a segue.
To perform a segue you should use performSegueWithIdentifier:,
for ex. [self performSegueWithIdentifier:#"showGuide" sender:self];,
in this case you need assign identifier to a segue in Xcode Interface Builder.
id try something like
UIStoryBoardSegue *segue = ... setup the one you want
[self performSelector:#selector(prepareForSegue:) withObject:seque afterDelay:0];
ive never worked with storyboards - but thats how you call a selector :)
Here is my code, posted in view1:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([segue.identifier isEqualToString:#"toLevels"])
{
levelViewController *vc = [segue destinationViewController];
vc.currentEnchantmentSelected = self.title;
}
}
This doesn't send the value of "self.title" to the variable in "levelViewController". Why is this? It sends it if I use a string.
Edit (levelViewController):
#synthesize enchantment = _enchantment;
- (enchantmentViewController *)enchantment
{
if (!_enchantment){
_enchantment = [[enchantmentViewController alloc] init];
}
return _enchantment;
}
the #property enchantment is declared in the header.
So from the chat, the issue was that you were setting this property in didSelectRowAtIndexPath:, which is actually called after prepareForSegue:sender: with storyboards. (when the segue is attached to a cell in a table)
So the solution is just to do that work directly in prepareForSegue:sender: instead. The sender will be the cell that was tapped. And if you need the indexPath for that cell you can use:
[self.tableView indexPathForSelectedRow]
Good luck with the app.
I've been debating with this for a while now, hope you can help me.
I've been creating an app using storyboards mostly, I have a point where I popup a modal box to add a new record, popup works fine, the problem is dismissing it.
I've followed Apple's instructions on how to properly close modal boxes using delegates, and that works fine, except I need to add a navigation controller to my modal box, because the add process requires two steps (here fullscreen):
The problem lies in setting the delegate, so here are my two questions:
1- In my root view class (My Tab) is a delegate of the Add class (the modal), everything is set up right except this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAdd"]) {
[[segue destinationViewController] setDelegate:self];
}
}
The problem lies in that [segue destinationViewController] is returning the navigationcontroller and not the AddDrinkViewController class (see the storyboard). How do I get around this? If I remove the navigation controller altogether, the code works fine setting the appropriate delegate.
2- Is there any way to set the delegate by dragging the outlets in the storyboard?
Thanks!
You're right, the destinationViewController will be a UINavigationController in this case. I wrote a category to handle this common situation:
// category .h file
#interface UIStoryboardSegue (NavControllerExtensions)
// Gets destinationViewCotroller. But if that controller
// is a NavigationController, returns the nav controller's
// top level view controller instead.
#property (readonly) id topLevelDestinationViewController;
#end
// category .m file
#implementation UIStoryboardSegue (NavControllerExtensions)
- (id)topLevelDestinationViewController
{
id dest = self.destinationViewController;
if ([dest isKindOfClass:[UINavigationController class]]) {
UINavigationController* nav = dest;
dest = nav.topViewController;
}
return dest;
}
#end
So now you can just do this in any of your prepareForSegue methods, and not need to worry about whether there even exists a NavigationController:
[[segue topLevelDestinationViewController] setDelegate:self]
// another example:
MyViewController *vc = segue.topLevelDestinationViewController;
vc.delegate = self; // etc.
To answer your second question, I couldn't find a way to set the delegate within IB.
I found a shorter way in my case (same as yours):
AddDrinkViewController *controller=[[[segue destinationViewController]viewControllers]objectAtIndex:0];
Basically you need to create an
Instance of UINavigationController and assign destinationViewController to it
and grab its topView controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAdd"]) {
UINavigationController *navigationController = segue.destinationViewController;
AddDrinkViewController *addDrinkcontroller = (AddDrinkViewController *)navigationController.topViewController;
addDrinkcontroller.delegate = self;
}
}