progres bar not showing ios - ios

I use the following code to get the tap on image view and navigate to another view controller:
-(void)tapDetected:(UIGestureRecognizer *)recognizer{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSLog(#"single Tap on imageview");
ImageTapGesture *sender = (ImageTapGesture *)recognizer;
UIStoryboard * storyboard = self.storyboard;
tele * detail = [storyboard instantiateViewControllerWithIdentifier: # "teledramaView"];
detail.imagelink = sender.imageLink;
detail.description = sender.description;
detail.id = sender.id;
[self.navigationController pushViewController: detail animated: YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
So far the code is working fine but the issue is the progress bar is not displaying properly.
It shows at the final moment before going to the other controller but the log comes before the progress bar: NSLog(#"single Tap on imageview");
Can anybody tell me why the progress bar is not working as it's meant to work? Thank you.

Well the answer is simple, since you are showing and hiding the the progressHUD in the same thread it will get removed as soon as it is added. Since you methods is executed on the main thread, which is also handeling any UI changes, your progressHUD will only be added after you method end. But since you remove the progressHUD on the last line it will also be removed directly. Even worse is that any code between adding and removing the HUD is blocking any UI changes.
You need to delay the loading a bit, to give the system time to present the progressHUD:
-(void)tapDetected:(UIGestureRecognizer *)recognizer{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSLog(#"single Tap on imageview");
[self performSelector:#selector(navigateToDetailView:) withObject:recognizer afterDelay:0.0];
}
-(void) navigateToDetailView:(UIGestureRecognizer*)recognizer{
ImageTapGesture *sender = (ImageTapGesture *)recognizer;
UIStoryboard * storyboard = self.storyboard;
tele * detail = [storyboard instantiateViewControllerWithIdentifier: # "teledramaView"];
detail.imagelink = sender.imageLink;
detail.description = sender.description;
detail.id = sender.id;
[self.navigationController pushViewController: detail animated: YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}

Related

Two UIToolBar appearing

We have UITableViewController in which we are giving table edit functionality like attached screenshot. And we want to show/hide bottom toolbar for bar button items.
for edit we are using below code.
[self.tableView setEditing:YES animated:false];
editButton.title = #"Cancel";
[self.navigationController setToolbarHidden:NO animated:YES];
After this code we are getting toolbar like the given image (two toolbars). How to remove white toolbar?
Thanks
Edit:
We are getting this issue when we are doing pushViewController:
TransactionsListViewController *callTransactionsListViewController=[[TransactionsListViewController alloc]initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:callTransactionsListViewController animated:YES];
In presentViewController we are not getting above issue:
TransactionsListViewController *callTransactionsListViewController=[[TransactionsListViewController alloc]initWithStyle:UITableViewStylePlain];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:callTransactionsListViewController];
[self presentViewController:navController animated:YES completion:nil];
In ViewDidLoad
[self.tableView setAllowsMultipleSelectionDuringEditing:YES];
[self.tableView setAllowsMultipleSelection:YES];
TableView Edit on button tap:
-(IBAction)btEdit:(id)sender{
if (self.tableView.editing)
    {
        [self.tableView setEditing:NO animated:false];
        editButton.title = #"Edit";
        [self.navigationController setToolbarHidden:YES animated:YES];
    }
    else{
        [self.tableView setEditing:YES animated:false];
        editButton.title = #"Cancel";
        [self.navigationController setToolbarHidden:NO animated:YES];
    } }
The white toolbar is not actually a toolbar. I think that when you show the toolbar for some reason table view gets twice offset from the bottom. It may be system issue or code in your application. It would be helpful if you could specify view and view controller hierarchy on this screen and any custom layout you apply to table view.

Xcode Can't Call/Dismiss viewcontroller from PopUp

This is going to take some explaining... So I'll do it in order:
I have a navigation controller where the rootViewController is called TipsCollectionViewController.
I have a UserViewController that's loaded as a popup:
UserViewController * userView = [[UserViewController alloc] initWithNibName:#"UserView" bundle:[NSBundle mainBundle]];
[userView setUEmail:email];
[self presentPopupViewController:userView animationType:MJPopupViewAnimationSlideTopBottom];
I then have another popup that loads on top of THAT popup:
Place *p = [placeArray objectAtIndex:indexPath.row];
DetailPlaceViewController *pvc = [[DetailPlaceViewController alloc] init];
[pvc setPlace:p];
NSLog(#"%#", p.PName);
[self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom];
Now there's a reason I've done this: the AppDelegate features a Navigation controller and previously I loaded the UserView like this:
[self.navigationController presentViewController:userView animated:YES completion:nil];
But this meant that the UserView would load on the iPhone but not on the iPad for some odd reason. But when I switched it to the popup view it worked fine.
So now I load both the UserView and the DetailPlaceView in a popup... but now it CLOSES on the iPad but not on the iPhone.
Here's the code for closing the detail view:
- (void) didTapBackButton:(id)sender {
NSLog(#"View Controller Number: %lu", (unsigned long)self.navigationController.viewControllers.count);
if(self.navigationController.viewControllers.count > 1) {
[self.navigationController popViewControllerAnimated:YES];
NSArray *stack = self.navigationController.viewControllers;
TipCollectionViewController *tipsVC = stack[stack.count-1];
[tipsVC.collectionView reloadData];
}
I know there's a better way to handle this whole thing... but what should I be doing differently?
UPDATE
If I switch it back to:
[self.navigationController pushViewController:userview animated:YES];
...for the UserView on the iPhone and:
[self.navigationController pushViewController:pvc animated:YES];
...for the view that loads after that, then the UserView will load... but the next viewcontroller (the DetailPlaceViewController) won't load. I think that's my main problem. I could probably dismiss the second view controller at that point if I could get it to load. Any ideas?
[self presentPopupViewController:pvc animationType:MJPopupViewAnimationSlideTopBottom];
if you are using this,presentPopupViewController is used to display like modal view which cant be dismissed without any custom cancellation action.
To use popOverViewController method, use pushViewController. Then that one you can dismiss by this technique.
Ultimately all I had to do was switch:
[self.navigationController pushViewController:pvc animated:YES];
to:
[self presentViewController:pvc animated:YES];
And it works. It opens and closes the view and everything works as it should.
I'm getting a warning on the DetailView once you click an item:
Presenting view controllers on detached view controllers is discouraged <UserViewController: 0x16e02020>
So I'll wait a couple of days to accept my answer. Otherwise, despite the warning, it seems to be working.

Displaying modal views programmatically

I want to be able to show a viewController when a button is pressed.
I don't want to use a navigation controller anymore, is there a way to display it using a modal?
Here is how I am currently showing the viewController:
- (void) editButtonDidClicked: (UIButton *) button {
EditViewController *viewController = [EditViewController getInstanceWithTag:button.tag];
[self.navigationController pushViewController:viewController animated:YES];
}
You can try below code
I assume that you are using storyboard.
UIStoryboard *board = [UIStoryboard storyboardWithName:#"name" bundle:nil];
viewController *controller = [board instantiateViewControllerWithIdentifier:#"Identifier"]; // Identifier is define in storyboard
[self presentViewController:controller animated:YES completion:nil];
Please check out this link if you are still facing the problem.
Hope this helps you.

Unable to trigger Segue to manually load VC - self.navigationController is Nil?

EDIT
After some more digging around it has become apparent that if i try to call a segue from the view controller class after a fast application switch to/from Safari i get an exception stating that the segue does not exist. It definitely does, in the VC that is loaded on screen, and i have checked the spelling and it's 100% correct.
What makes it even weirder is that if i call that exact same method from an IBAction it works fine.
Here's the code i am using:
-(void)goToPhotoPage{
[self performSegueWithIdentifier:#"twitterAuthComplete" sender:self];
}
If i call this when the app resumes i get an exception, however if i call it from this IBAction, attached to a UIButton, with doing nothing different the segue works as expected and no exception.
- (IBAction)twitterToPhoto:(id)sender
{
[self goToPhotoPage];
}
Arrrrgrghrhhgrgrg!
ORIGINAL QUESTION
I am working on an iPad application that uploads user photos to Facebook/Twitter.
As part of the process i have to jump to Safari to do OAuth for twitter, the app then jumps back via a specific URL and get's the tokens e.t.c
However for some reason when the application re-awakes i cannot trigger any segue's or manually load any VC's.
I have a success block in my AppDelegae which get's called when the upload is complete which calls a method in the VC to close a spinner and segue to the success view.
The spinner stops as expected, but no matter what i try i cannot get the segue to work.
Everything is hooked up, the segue has an ID and i get no error or exceptions in the console, just nothing happens. The only way i can get code triggered segue to work after this point is to use a user trigger one connect to a UIButton, after that one complete they start to work again.
Here is the code with callback in my AppDelegate:
- (void)postToTwitter:(NSString*)postText image:(UIImage*)image
{
NSData *data = UIImageJPEGRepresentation(image, 0.5);
[_twitter postStatusUpdate:postText
mediaDataArray:#[data]
possiblySensitive:nil
inReplyToStatusID:nil
latitude:nil
longitude:nil
placeID:nil
displayCoordinates:nil
uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
} successBlock:^(NSDictionary *status) {
ViewController * vc = [[ViewController alloc]init];
[vc triggerSuccess];
} errorBlock:^(NSError *error) {
ViewController * vc = [[ViewController alloc]init];
[vc uploadFail:error];
}];
}
in the VC i have tried the following:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
[self.navigationController performSegueWithIdentifier:#"approveSegue" sender:self];
}
As well as:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"done"];
[self.navigationController pushViewController:controller animated:YES];
}
In a moment of pure desperation i even tried:
- (void)triggerSuccess
{
[self segueToSuccess];
}
- (void)segueToSuccess
{
[self hideMessage];
//[self.navigationController performSegueWithIdentifier:#"approveSegue" sender:self];
[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
[self performSelector:#selector(segueToSuccessPart2) withObject:nil afterDelay:0.25];
}
- (void)segueToSuccessPart2
{
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"done"];
[self.navigationController pushViewController:controller animated:YES];
}
I've obviously missed something, and i'm guessing it's to do with the application going into the background and the VC being "unloaded" from memory, and needing re-instatiating, but i'm not sure where to begin with that.
Any help would be greatly appreciated as i'm about to throw the computer out of the window . .
Thanks
Gareth
Edit 1
After doing some more troubleshooting it appears that during this call in the VC:
[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
self.navigationController is nil . . .
I'm guessing that is likely the cause of the issues i'm seeing?
Edit 2
So as suggested by Kelin, i am trying to make sure i retain the Navigation Controller.
I have done the following in AppDelegte:
#property (nonatomic, strong) UINavigationController *navController;
and
#synthesize navController;
But when i try to access this from the VC using the below code, it's still nil . .
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
UINavigationController *navController = appDelegate.navController;
[self dismissViewControllerAnimated:NO completion:nil];
[navController popToRootViewControllerAnimated:NO];
Edit 3
I have also added this to the AppDelegate, which means the Navigation Controller is no longer nil. But still nothing happens . . .
if (!self.navController)
{
self.navController = [[UINavigationController alloc]initWithNibName:#"Main" bundle:nil];
}
The problem is you trying to perform segue from storyboard using programmatically created View Controller.
You use -performSegueWithIdentifier: sender: completely wrong. In this method "sender" is a button, or any other control which action initialises segue, but not the view controller to be pushed.
Usually segue is created with storyboard. But if you really need to create it manually, call:
-[UIStoryboardSegue initWithIdentifier:source:destination:]
where source and destination are view controllers.
Read this: https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-storyboard/StoryboardSegue.html
or this (about custom segues):
You can not do both dismiss and pop together either you have to pop or dismiss the view controller and
Every ViewController have it's own NavigationController which is default point out to navigation controller you added to AppDelegate.
So, You also can access it by self.navigationController (Edit 3)
Also check whether you initialised navigation controller in
AppDelegate
self.navController = [[UINavigationController alloc] initWithRootViewController:firstVC];

ViewController being held in memory

I use the following code to switch between view controllers..(works fine) I have many view controllers too by the way Im not just switching back and forth between 2
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
MyTableViewVC *detailView = (MyTableViewVC *)[storyboard instantiateViewControllerWithIdentifier:#"MyTableViewVC"];
//pass data through to VC
[self presentViewController:detailView animated:NO completion:nil];
I see the memory use climbing as I transition between view controllers
So i did some research and realized Im not dismissing the previous view controller. I use the following code [self dismissViewControllerAnimated:NO completion:nil]; before I call presentViewcontroller: (I also tried using it after) and it doesn't work. If i use it after nothing happens.. using it before I get the following warning
Thread 1:EXC_BAD_ACCESS(code=1.... blah blah let me know if you need the rest
Ive also tried to do something like this..
[detailView presentViewController:detailView animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
What am I doing wrong?
Below is the code to remove VC from the navigation stack.
NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
// [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack.
[navigationArray removeObjectAtIndex: 2]; // You can pass your index here
self.navigationController.viewControllers = navigationArray;
[navigationArray release];
However note, by doing this you will have problem to go to previous VC as you are removng the previous VC from the stack.
As you are complaining about memory, I would say DOUBLE CHECK code once again and investigate where memory is getting used more. Incase if that object is not needed, release that object so that memory issue would not be there.
If you want to back to root view controller, you must use this code.
[self.navigationController popToRootViewControllerAnimated:YES];

Resources