How to present modal view in "parentViewController"? - ios

I'm trying to write iPad app.
I have UIViewController as parentViewController (full screen) for masterView and detailView (my handmade splitView). Also I have a separate view (for example moreDetailView) with class and xib, which I would like to show as modal.
masterView has UITableView and detailView has UICollectionView. Both of them has own classes and xib. In detailView there are several items.
In my didSelectItemAtIndexPath: of detailView I would like to show moreDetailView.
So, how can I do that? And how to show it in parentViewController, but NOT in detailView.
Hope my question is understandable.

The code below will present your controller in a modal formsheet (you can change this with the setModalPresentationStyle) on the top of your splitView.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}]; }

You are initializing your masterview and detailview in parentview. To access the parentcontroller you can declare a property in detailcontroller as
UIViewController *parent;
and while initializing you can do
detailController.parent=self;
and while showing modal you can do
[parent presentModal]; //instead of [self presentModal];
I hope above works for you, you will need to correct the syntax though.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *moreDetailViewController = [[MoreDetailViewController alloc] init];
[moreDetailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; //or style depending on what you want
[moreDetailViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:moreDetailViewController animated:YES completion:^{
//stuff you want to do after the viewController has been presented
}];
}

Related

UISearchBar Staying at top when seguing from tableview results

I created a search with 2 UINavigationcontrollers and with 2 UITableViewControllers. One for displaying the initial results, and then another TableViewController for when displaying searched results.
This is where i think the issue occurs. I use this method to show the resultsTableViewController where i make it the top view controller.
Now when i segue from the results view controller, the UISearchBar stays on top. When i code [vc.tableView setDelegate: self];.
it removes the issue of the search bar staying but then screws up the didselectrowatindex path which i need to identify because the results aren't the same from the original and the results Tableviewcontroller.
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
// Set searchString equal to what's typed into the searchbar
NSString *searchString = self.searchController.searchBar.text;
[self updateFilteredContentForAirlineName:searchString];
// If searchResultsController
if (self.searchController.searchResultsController) {
UINavigationController *navController = (UINavigationController *)self.searchController.searchResultsController;
// Present SearchResultsTableViewController as the topViewController
SearchResultsTableViewController *vc = (SearchResultsTableViewController *)navController.topViewController;
// Update searchResults
vc.searchResults = self.searchResults;
// And reload the tableView with the new data
[vc.tableView reloadData];
}
}
Here's a project i mocked up that has the issue included.
http://expirebox.com/download/10533c5d386618b95bb39bd1dc886ace.html
try to extend your next viewcontroller to class.so i will create new data class and extend to viewcontroller than paste this code in didSelectRowAtIndexPath: method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
data *next=[self.storyboard instantiateViewControllerWithIdentifier:#"datascreen"];
[self presentViewController:next animated:YES completion:nil];
}
ok bro try this
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
data *next=[self.storyboard instantiateViewControllerWithIdentifier:#"datascreen"];
[self.navigationController next animated:YES];
}
both class use this code.try this if any problem than tell me

How do I correctly display a UINavigationController when tapping a UITableViewCell?

I'm new to iOS development. I have an app that has a UINavigationController (with an embedded UITableViewController, call it TableView1) and I need to display another UITableView (TableView2) on the tap of a UITableViewCell for TableView1.
I did some online searching and didn't really find anything super useful, but what I was able to find said that I have to present TableView2 instead of pushing it. Everything is working correctly, except that TableView2 doesn't have a back button and I have to create my own UIBarButtonItem and assign to leftBarButtonItem of the navigationItem.
This is all fine, except for the fact that I can't help but feel like I'm doing it wrong. Is there any easier way (or a more correct way) to accomplish what I'm trying to accomplish?
Code for TableView1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewController *tableViewController = [[UITableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
[self.navigationController presentViewController:navigationController
animated:YES
completion:nil];
}
EDIT: Along with this question, if I find out I'm doing this the correct way, how do I get the normal back button to display? or can I?
Present it directly from that view controller:
[self presentViewController:navigationController animated:YES completion:nil];
Or use pushViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewController *tableViewController = [[UITableViewController alloc] init];
[self.navigationController pushViewController:tableViewController animated:YES];
}

UIView Frame Changes on dissmissviewcontroller

I have UIVIewController & UITableViewContoller in my project.I am presenting UITableViewController on UIButton action in first UIVIewController and select data from tableview to display in my First UIVIewController using Protocol Method.
tableViewController *objPlanTable = [self.storyboard instantiateViewControllerWithIdentifier:#"presentTableView"];
objPlanTable.myDelegate = self;
objPlanTable.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:objPlanTable animated:YES completion:nil];
This is my UITableViewDelegate Method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *aCell = [tableView cellForRowAtIndexPath:indexPath];
if([self.myDelegate respondsToSelector:#selector(selectPlan:)])
{
[self.myDelegate selectPlan:aCell.textLabel.text];
[self dismissViewControllerAnimated:YES completion:NULL];
}
if ([self.myDelegate respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
[self.myDelegate backgroundChanger];
}
}
But on Completion it changes my UIVIew Height which contains UIButton. This UIVIew is UIViewController>>UIView>>UIScrollView>>UIView
How do i keep my this UIView as it is before UITableViewController presented;
I found similar question on StackOverFlow UIView Frame Issue,but it is for push UIVIewContoller & did not helped.
Please Correct me if i am doing anything wrong,Any Idea/Help will be appreciated.
Done, set my ui to original state before UIViewController presented on protocol Method.
Alternate is to Push rather than Present UIViewController.

Flip Transition from a Tableview Custom Cell to a UIViewController

I created a custom tableview cell that gets displayed in my tableview. Upon user tapping the cell, I would like to create a flip horizontal transition to a new view controller. How to do this either using Core Animation or UIView?
Sorry I am a newbie can't find the right way to do it anywhere.
Thank you in advance.
I guess You are talking about this.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create the next view controller.
DetailViewController *detail= [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[detail setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:detail animated:YES completion:nil];
}
For Dismiss:
-(IBAction)close:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
write this method in DetailViewController and call this method to back.

UITabBar disappears when selecting UITableViewCell

I have a UITableView with a cell named 'Sunset'. Upon pressing the UITableViewCell, the view switches to 'infoView' which loads some text from a .txt file. When pressing the 'back' button, the view switches back to the UITableView but there's a problem. After loading the view, the UITabBar is gone! Since it is gone, it is impossible to go back to another view.
I have tried:
self.hidesBottomBarWhenPushed = NO;
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cellSelected = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellTitle = cellSelected.textLabel.text;
if (cellTitle == #"Sunrise")
{ //Swap views
informationView *iv = [[informationView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:iv animated:YES];
}
}
Of course the tab bar doesn't show. You are presenting the second view modally. If you want to keep this implementation you are going to have to add a button or something on the second view that will perform
[self.navigationController dismissModalViewControllerAnimated:YES]; //Programatically dismiss the view controller
If you want to keep the tabBar and the navigation bar functionality, you should use
[self.navigationController pushViewController:iv animated:YES];
instead of
[self presentModalViewController:iv animated:YES];

Resources