TableViewController presented modally does not scrolls to bottom - ios

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

Related

Cant navigate to other Viewcontrollers from a commonViewController's tableview click

I have a commonViewController to pop up on other viewcontrollers and the commonViewController has a view and a tableview inside it and also some other components. I have populated that view successfully on other viewcontroller pages, but the problem is; when iam trying to navigate to some other viewcontroller pages while iam clicking the rows in commonViewController's tableview.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1)
{
EditProfileViewController *nextViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];
}
}
I have tried both presentViewController and pushViewController but it is not navigating anywhere. What is the issue. Please help me.
Get reference to your storyboard and load viewcontroller using identifier:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];

While pushing a viewcontroller there is a jerk in animation

For pushing a view controller I'm using following code. On tap of UITableViewCell need to push DetailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row)
{
NSDate *object = self.objects[indexPath.row];
DetailViewController *controller = [DetailViewController new];
[self.navigationController pushViewController:controller animated:YES];
}
}
Now problem is I get a jerk while animating. Refer to screenshot
its because of transparency. just set a background color for your viewcontroller. thats all.
Most probably you're doing something "heavy" on the main thread, while loading DetailViewController.
Could you show us what are you doing in DetailViewController?
I think there is issue with allocating object and pushing same object.
Do the following changes, it will work fine.
Your code :
DetailViewController *controller = [DetailViewController new];
[self.navigationController pushViewController:controller animated:YES];
Replace :
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
MyViewController *controller = (MyViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"<your Storyboard ID>"];
it will work fine at my end.
Hope this help you.

Segue from Table View Cell xib with disclosure Indicator to storyboard

I am new in iOS programing and I have an issue. I have a customized table view cell with disclosure indicator in a separate xib file and I want to call a viewcontroller which is in storyboard when the user taps the cell.
Here is the customized table view cell :
Here are the table view (class : TableViewController) that displays the custom table cell and the view (class : ViewController) I want to call when the user taps the customized table view cell :
Does the view I want to call have to be in a separate xib file or can I let it in my storyboard? What is the best solution?
Just use didSelectRoWAtIndexPath method of table view …DO something like this..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NSString* viewType = #"YourVCIdentifier";//u can have ContactVC or NavC as other options depending on ur condition
UIViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:viewType];
[self.navigationController pushViewController:viewController animated:YES];
}
that will do it
Use the UITableViewDelegate method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
and push the view controller manually.
Assign a storyboard ID to the view controller in the storyboard, and then do something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:#"your_view_controller_storyboard_ID"];
[self.navigationController pushViewController:destVC animated:YES];
}
This is where you assign a storyboard ID to your view controller:
And don't forget to set your view controller as your tableView delegate :)

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

Loads viewcontroller but does'nt present until second tap on tableview

When i tap my tableview this code gets executed:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
ViewController *vc =[storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
vc.currentCategory = indexPath.row ;
[self presentViewController: vc animated:YES completion:nil];
}
Everything seems to load and it breaks on the breakpoints in the new viewcontroller. But it doesnt get presented. If i tap a second time it does'nt execute the code but it presents the viewcontroller. If i go animated: NO, everything works on the first tap, but not with animated: YES. Any ideas what might be wrong?
I just had the exact same problem and it turned out to be a threading issue. You need to call your presentViewController inside of the following:
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(controller, animated: true, completion: nil)
})
Keep in mind, my answer is using Swift, it should be a simple translate back to objective-c though, but I'm pretty sure your running into a threading issue like I was. Hope this helps people.
Give this a go:
UIView *containerView = self.view.window;
[containerView.layer addAnimation:NO forKey:nil];
UIViewController * otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:otherViewCon animated:NO completion:nil];

Resources