Alert View Click not calling instantly like iOS 6 in iOS 7 - iphone

In my application while user go to the next view controller I am showing indicator with cancel button. On cancel button click i m setting value -2 for one variable like appDel.Val = -2; And before push to next controller i m checking that if appDel.Val = -2; then return. So no need further process.
this is working fine with iOS6 devices. When user tap on cancel in UIAlertView Delegate method for Alert click calls immediately and value set for appDel.Val=-2. So it will return without any further process.
Bit With iOS7 it creating issue like when user tap on cancel in alert, alertview delegate method is calling after completing current process for push view controller. So appDel.Val=-2 will be set after push controller from alert click method as alert delegate method is not calling immediately same like iOS 6
Can any one please suggest, How can i fix this for iOS 7?
Here is my code.
-(void)goToNextViewController:(NSDictionary*)outputDictionary
{
myViewController *mtvc=[appDel.myDict valueForKey:[outputDictionary valueForKey:#"id"]];
if (mtvc) {
[appDel showindicator:#"Please Wait..."];
}else{
[appDel showindicator:#"Connecting..."];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
self.rootDict = [[NSMutableDictionary alloc] initWithDictionary:outputDictionary];
appDel.activeId = [outputDictionary valueForKey:#"id"];
if(!mtvc)
{
myViewController *mtvc = [[myViewController alloc]initWithNibName:#"myViewController" bundle:nil];
appDel.tempViewController=mtvc;
appDel.tempViewController.isVeryFirst = YES;
[mtvc release];
}
else
{
appDel.tempViewController=mtvc;
appDel.tempViewController.isVeryFirst = NO;
#try {
[self.navigationController pushViewController: mtvc animated: YES];
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
}
[appDel performDismiss];
return;
}
if (appDel.Val==-2)
{
[appDel.newConnections removeObjectForKey:appDel.activeId];
appDel.tempViewController.isNewConnection = NO;
appDel.Val = 0;
[appDel performDismiss];
return;
}
[appDel.newConnections setObject:appDel.tempViewController forKey:[outputDictionary valueForKey:#"id"]];
[self.navigationController pushViewController: appDel.tempViewController animated: YES];
[appDel performDismiss];
}
Alert click
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alert.tag==654)
{
self.Val = -2;
[baseAlert dismissWithClickedButtonIndex:0 animated:YES];
baseAlert=nil;
}
}
Thanks for any help.

Related

Wait UIAlertView Button

I have this code in my Application:
if (self.uiSwtichState == TRUE)
{
if ([CLLocationManager locationServicesEnabled])
{
[self.textString stringByAppendingString:[[[SMSLocationModel alloc] init] getLocation]];
}
}
MFMessageComposeViewController *sms = [[MFMessageComposeViewController alloc] init];
sms.messageComposeDelegate = self;
sms.body = self.textString;
sms.recipients = self.arrayOfNumbers;
[self presentModalViewController:sms animated:YES];
this code is into a method called "send".
As you can imagine, the method getLocation get the current user location and, the first time the Application run, a UIAlertView appear on the screen asking the user if he want to allow the application to get his location.
The problem is that when this UIAlertView appear, she is immediately replaced by the sms Vie Controller (MFMessageComposeViewController) and in this way the user doesn't have enough time for answer YES or NO in the UIAlertView.
There is a way for wait that the user press a button in the UIAlertView and THEN present the ModalViewController?
Thanks!
you could use the CLLocationManagers delegate method to wait until the authorization state changes. Save the sms viewController to an instance variable if you are not authorized to use location services. then ask the location manager to authorize you. If the authorization state changes present that view controller.
// somewhere else
self.locationManager.delegate = self;
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(#"New Authorization State: %d", status);
if (self.viewControllerToPresentAfterLocationDidChange) {
if (status == kCLAuthorizationStatusAuthorized) {
// set location of viewController
[self presentViewController:self.viewControllerToPresentAfterLocationDidChange animated:YES completion:NULL];
}
else {
// user did not authorize you to use location services
}
self.viewControllerToPresentAfterLocationDidChange = nil;
}
}
- (IBAction)buttonPressed:(id)sender {
UIViewController *vc = [[UIViewController alloc] init];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
// authorized already, no alert will appear.
// set location of vc
[self presentViewController:vc animated:YES completion:NULL];
}
else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined){
self.viewControllerToPresentAfterLocationDidChange = vc;
// access location so alert will show
}
else {
// not authorized or restricted.
}
}
Maybe you can use this delegate:
- (void)didPresentAlertView:(UIAlertView *)alertView{
}
For example, initializing a boolean which can prevent of presenting this modal view controller. Then if dismissed change the boolean to allow presenting this view controller.
Yes, you can implement the AlertViewDelegate.
See UIAlertViewDelegate Documentation for further information.
Then you can use the alertView:clickedButtonAtIndex: method and present your MessageComposer when the user has clicked the alert view.

how can i push a view only once with in a method calling multiple times in iphone

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
ChatViewController *chatView;
if(contactView==nil)
{
chatView=[[ChatViewController alloc] initWithNibName:#"ChatViewController" bundle:nil];
}
[self.navigationController pushViewController:chatView animated:YES];
[messageDelegate newMessageReceived:m];
}
The above delegate method called for every incoming message.When it called, it goes to a new UIViewController.Here my problem is a view pushed multiple tinmes,so error will be occered.how can i fix this error in iphone
Add this snippet before pushing the view controller
BOOL viewControllerAlreadyPushed = NO;
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[ChatViewController class]]) {
viewControllerAlreadyPushed = YES;
}
}
if(!viewControllerAlreadyPushed) //if not pushed, push it
{
ChatViewController *chatView;
if(contactView==nil)
{
chatView=[[ChatViewController alloc] initWithNibName:#"ChatViewController" bundle:nil];
}
[self.navigationController pushViewController:chatView animated:YES];
[messageDelegate newMessageReceived:m];
}

SMS option not working properly

I am using xcode 4.2 and i am developing an iphone APP , part of this app is sending SMSs
here is the code that I typed:
-(IBAction)SMSbutton{
MFMessageComposeViewController *sms = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText]) {
sms.body= [NSString stringWithFormat: #"text"];
sms.messageComposeDelegate = self;
[self presentModalViewController:sms animated:YES];
}
I can open the SMS application and send SMS but the problem is whether I click on the "cancel" or the "send" button the message application does not go away . how to do that ?
thanks
Set your calling class to be a delegate of the message composer, then catch the cancel and send events to dismiss the modal view controller as needed.
Set your header file to adhere to the MFMessageComposeViewControllerDelegate, and when you initialize the composer, set the message delegate to self:
MFMessageComposeViewController *george = [MFMessageComposeViewController alloc] init];
george.messageComposeDelegate = self;
Then implement the delegate method...easiest way is:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
}
...but you can catch and deal with errors and events as necessary.
Implement messageComposeViewController:didFinishWithResult: in your delegate"
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
if(result == MessageComposeResultCancelled) {
//Message cancelled
} else if(result == MessageComposeResultSent) {
//Message sent
}
[self dismissModalViewControllerAnimated:YES];
}
Have you tried dismissViewControllerAnimated:completion: or dismissModalViewControllerAnimated:?
[self dismissModalViewControllerAnimated: YES];

dismissing modalViewController of modalViewController

So I have a UITabBarController app and I want to display a login page, and so I did:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(userDidLogin:) name:UserDidLoginNotification object:nil];
LoginViewController* loginViewController = [[LoginViewController alloc] init];
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
[self.tabBarController.selectedViewController presentModalViewController:loginViewController animated:NO];
[loginViewController release];
Inside my LoginViewController I can as well show another modalViewController:
- (void) twitterLogin: (UIViewController *) askingView
{
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _twitter delegate: self];
if (controller) {
self.askingView = askingView;
[askingView presentModalViewController: controller animated: YES];
}
}
I have the following method where the askingView is the LoginViewController,
when I want to dismiss this I do:
[self.askingView dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidLoginNotification object:nil];
However, this doesn't dismiss the LoginViewController and show the UITabBarController views.. it just dismisses my modalViewController shown from the LoginvVIewController. What am I doing wrong here? I am also getting the following error:
attempt to dismiss modal view controller whose view does not currently appear. self = <LoginViewController: 0x2aff70> modalViewController = <SA_OAuthTwitterController: 0x2d2a80>
2011-09-16 09:45:37.750 VoteBooth[4614:707] attempt to dismiss modal view controller whose view does not currently appear. self = <MainViewController: 0x29fec0> modalViewController = <LoginViewController: 0x2aff70>
In order to dismiss a modal view that is presented over another modal view, you have to call dismissModalViewControllerAnimated: on the parent of the parent. I have used this in some of my apps and it has worked beautifully for me (after many painstaking hours trying to figure it out). Here is exactly what I've used:
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];
if ([self respondsToSelector:#selector(presentingViewController)]) {
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}
If you have a dynamic UX and do not know how many parents to go to, you can use this recursive function to figure it out...
- (void) goHome
{
//Dismiss modal back to home page
int numberOfVcsToDismiss = [self findRootViewController:self];
[self dismissToRootVc:numberOfVcsToDismiss];
}
- (int) findRootViewController:(UIViewController*)vc
{
if(vc)
{
return 1 + [self findRootViewController:vc.presentingViewController];
}
return 0;
}
- (void) dismissToRootVc:(int)count
{
if(count == 1)
[self dismissViewControllerAnimated:YES completion:^{}];
if(count == 2)
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{}];
if(count == 3)
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{}];
if(count == 4)
[self.presentingViewController.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{}];
if(count == 5)
[self.presentingViewController.presentingViewController.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{}];
//etc....
}

Cancel and done button does not work in new contact view

I am trying to integrate new contact control in my app. Here is my code:
- (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
return YES;
}
-(IBAction)addcontact:(id)sender{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
[picker release];
[navigation release];
}
It pops up new contact view but when I click Cancel or Done button nothing happens.
Can anyone help me?
Thanks in advance!
//Make sure your VC is an <ABNewPersonViewControllerDelegate>
-(void) newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
if (person != nil) //nil = Cancel button clicked
{
//do something
}
//iOS6
[self dismissViewControllerAnimated:YES completion:nil];
}
You need to add methods that should be called when the cancel or done button is tapped and that method should call [self.navigationController dismissModalViewController