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

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

Related

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

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.

Is there a way to dismiss the current ViewController after presenting another?

After some time searching for an answer, I have to admit that i'm pretty confuse with this case.
At my job, I'm asked to do something really specific :
I have to present a UIViewController on a previous UIViewController, actually, the current ViewController dismiss itself before the second appear. That give the whole thing a funny animation that a ViewController goes down and another rise from the bottom after this. But... It's not really "pro" and, we're able to see the rootViewController behind the scene during the animation.
So, I have to precise that there is NO NavigationController, that would have made this a lot easier in my opinion, so I'm forced to do it with two UIViewController, and there is my actual code :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"userViewController"];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:YES completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
It is call right after a button is pressed, so there is no problem with the actual ViewController viewDidLoad or viewDidAppear I think.
But each time this code runs, I get the following error :
[1163:17641] Warning: Attempt to present <UserViewController: 0x7b0f0a00> on <EIHomeViewController: 0x7b0d2a00> whose view is not in the window hierarchy!
I don't really know how I could manage to keep a trace of the current UIViewController to dismiss it in the next ViewController viewDidAppear to be sure there will be no "blackout" on the screen.
Thank you for your help in advance!
Try this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"userViewController"];
[self dismissViewControllerAnimated:NO completion:^{
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:NO completion:nil];
}];

Presenting new ViewController from different storyboard - strange delay

I have noticed strange behaviour.
When i'm presenting new viewController that is initiated programatically from different storyboard and flag animated is set to YES there is huge delay before ViewController is shown.
UINavigationController * enterVC = [[UIStoryboard storyboardWithName:#"Survey_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"echoEntryVC"];
[self presentViewController:enterVC animated:NO completion:nil];
When flag is set to NO view Controller is presented immediately.
UINavigationController * enterVC = [[UIStoryboard storyboardWithName:#"Survey_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"echoEntryVC"];
[self presentViewController:enterVC animated:YES completion:nil];
Does someone have the same problem? Any explanation would be good :)

self.tabBarController dismissViewControllerAnimated doesn't work

I have a UITabBarController in my application.
I would like to present from one tab, another UIViewController.
So I wrote in ViewControllerA (which is a tab in the tabviewcontroller):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MyViewController *chooseTemplateController = [storyboard instantiateViewControllerWithIdentifier:#"myController"];
[self.tabBarController presentViewController:myController animated:NO completion:nil];
This shows MyViewController nicely.
However, how can I dismiss MyViewController?
I read in many questions that I need to call:
[self.tabBarController dismissViewControllerAnimated:NO completion:nil];
However - where do I call it from? I tried from MyViewController - but since it's not part of the UITabBar, self.tabBarController is null.
I initialize the UiTabBarController from storyboard and not from appDelegate and I would like to leave it that way.
Use the presented viewController's presentingViewController property
Objective-C
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
Swift
presentingViewController?.dismissViewControllerAnimated(false, completion: nil)
You can also use this shorthand version (I don't recommend you do, but you will see it often)
Objective-C
[self dismissViewControllerAnimated:NO completion:nil];
Swift
dismissViewControllerAnimated(false, completion: nil)
see
Dismissing a Presented View Controller

Resources