UIView Frame Changes on dissmissviewcontroller - ios

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.

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

TableViewController presented modally does not scrolls to bottom

I'm currently having a CollectionViewController which by clicking on cells will display the detail view controller (TableViewController).
Code for displaying TableVC modally:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *detailVC = [storyboard instantiateViewControllerWithIdentifier:#"DetailTimetableViewController"];
[self presentViewController:detailVC animated:true completion:nil];
Things are working fine with the code above, the Table View Controller is presented modally and the scroll is behaving properly.
However, i followed this tutorial (http://blog.matthewcheok.com/design-teardown-preview-expanding-cells/), which creates a custom UIViewControllerAnimatedTransitioning, I've had everything from the tutorial to be working completely fine.
Code for display TableVC modally (with custom animation):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *detailVC = [storyboard instantiateViewControllerWithIdentifier:#"DetailTimetableViewController"];
ExpandingCellTransition *transition = [[ExpandingCellTransition alloc]init];
detailVC.transitioningDelegate = transition;
[self presentViewController:detailVC animated:true completion:nil];
However, everything is working fine except for when the TableViewController is presented, it doesn't allows scrolling to the bottom, and is restricted at certain height.
I've tried searching for similar problems (TableViewController unable to scroll to bottom), and tried applying their solutions but none of it works, I believe the cause of problem to be from the custom transition delegate.
set tableviewProperty tableview.UITableViewAutomaticDimension = YES
Try this
// Obj-C
self.automaticallyAdjustsScrollViewInsets = NO;
// Swift
self.automaticallyAdjustsScrollViewInsets = false
hope may help you
use following code in cellForrowAtindexPath delegate method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<##"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
In the MainViewController viewDidLoad method, add the following code: self.automaticallyAdjustsScrollViewInsets= NO

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.

How to present modal view in "parentViewController"?

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
}];
}

reload data uitableview from another view

I want to reload data of UITableview from another UIView.
(the UITableview is in ListNoteViewController)
the call I do from DetailViewController (the other uiview) is :
ListNoteViewController *controller = [[ListNoteViewController alloc] initWithNibName:#"ListNoteViewController" bundle:[NSBundle mainBundle]];
[controller.TableNotes reloadData];
but nothing happens. Please, someone can help me ?
Advanced thanks
You can use delegates.
in DetailViewController.h
#property (nonatomic, strong) id Delegate;
In ListNoteViewController.m
-(void)myTVReloadMethod {
[myTable reloadData];
}
And when you are going to DetailViewController
DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
dvc.Delegate = self;
[self.navigationController pushViewController:dvc animated: yes];
In any method in DetailViewController
[delegate performSelector:#selector(myTVReloadMethod) withObject:nil];
Nothing will happen, because you are trying to reload a tableview which is not yet created!
The UI elements like UITableView, UILabel etc will be created only after the view of the particular UIViewController is loaded. Here you have just initialised the viewcontroller only.
So you should write this in
-(void)viewDidAppear:(BOOL)animated
{
[self.TableNotes reloadData];
}
OR
-(void)viewWillAppear:(BOOL)animated
{
[self.TableNotes reloadData];
}
of your ListNoteViewController.
This is the problem with your code. And in case, if the ListNoteViewController is already in stack,ie, if you have already loaded the same viewcontroller and is now trying to reload the tableview on it, then you can use custom delegates to achieve the same.
you can see how to add a delegate here.

Resources