wait_fences: failed to receive reply: 10004003 - what? - iphone-sdk-3.0

Been getting this odd error.
heres the deal - in the below method i have an alert view come up, take a U/N and PW, then atempt to start another method.
The method
-postTweet
does not get activated
I just get this error in console
wait_fences: failed to receive reply: 10004003
Which is really odd - as ive never seen it before
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView == completeAlert ) {
if (buttonIndex ==1) {
passPromtAlert = [[UIAlertView alloc] initWithTitle:#"Enter Name" message:#"Please enter your Username and password - they will be saved\n" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Tweet", nil];
[passPromtAlert addTextFieldWithValue:#"" label:#"Enter username"];
[passPromtAlert addTextFieldWithValue:#"" label:#"Enter password"];
textField = [passPromtAlert textFieldAtIndex:0];
textField2 = [passPromtAlert textFieldAtIndex:1];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
textField.autocorrectionType = UITextAutocapitalizationTypeNone;
textField.textAlignment = UITextAlignmentCenter;
textField2.secureTextEntry = YES;
textField2.clearButtonMode = UITextFieldViewModeWhileEditing;
textField2.keyboardType = UIKeyboardTypeAlphabet;
textField2.keyboardAppearance = UIKeyboardAppearanceAlert;
textField2.autocapitalizationType = UITextAutocapitalizationTypeWords;
textField2.autocorrectionType = UITextAutocapitalizationTypeNone;
textField2.textAlignment = UITextAlignmentCenter;
[passPromtAlert show];
}
}
if (alertView == passPromtAlert ) {
if (buttonIndex == 1) {
NSLog(#"here");
[self postTweet];
}
}
}
Any help would be appreciated
Thanks
Sam
ADDED:
If you need to see more code, then let me know

Here I was also facing the same issue in my project and I managed to solve the issue now. You need to call the method using NSTimer.
So, Here you are calling one alert inside another alert means when one alert dismiss then the new alert you are calling there. There is no problem in that. You can do it easily. Instead of defining alertview inside the method "- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView == completeAlert )", You can create one method e.g. "Show_AlertMessage" and call it using timer like this.
[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:#selector(Show_AlertMessage) userInfo:nil repeats:NO];
Let me know if you can get rid of this issue. We will solve this issue as I did for my side.

I believe the problem is caused by you creating another alert view before you dismiss the first one. Since only one alert view is supposed to be present at anyone one time the second alert view is stepping on the first one.
You need to dismiss the first view before creating and showing the second.

Solution is here! I had same error, now i got the solution, this may help you. Use this delegate of AlertView
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

Your UITextField* isn't resigning its firstresponder status before the alert is dismissed.
This messes up the responder chain. Add [textField resignFirstResponder] or [textField2 resignFirstResponder] as applicable in the UIAlertViewDelegate implementation (alertView:clickedButtonAtIndex:)
Also, schedule your second UIAlertView to show after the first is dismissed (you can do this using (performSelector:withObject:afterDelay:)

Related

Why is the UIAlertView not blocking until user responds by tapping a button?

In my iOS 7 app, I need to verify the user wants to deleta a selected record from Cord Data. I have the UIAlertViewDelegate defined in the .h file. This is the code to display the alert:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning"
message:#"Are you sure you want to delete this record?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Delete", nil];
[alert show];
if(alertButtonTapped == 0)
return;
// remainder of code to delete record follows (was omitted)
This is the code to check which button was tapped:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
alertButtonTapped = [NSNumber numberWithInteger:buttonIndex];
return;
}
The problem is the alert is displayed and then immediately falls through the remainder of the code in that method. I have never seen this before; usually it blocks until the user has responded by tapping one of the buttons (at least I thought it did). What do I need to do to make this alert block until the user responds? (I was looking at UIAlertView blocks, but not sure that would do the job since it appears to use a different thread)
This is how UIAlertView works -- it doesn't block, thus why it has the UIAlertViewDelegate methods for actually implementing a response.
If the "remainder of code" is what should happen after they tap a button (e.g. the "Delete" button), then move all of that code into the delegate method, like:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != alertView.cancelButtonIndex) {
// code to delete record
}
}
EDIT - adding example to answer a comment
So if you have multiple UIAlertViews in the same class, you could differentiate between them using the tag attribute of UIView (UIAlertView is-a UIView). So it could be something like this:
const NSInteger kDeleteAlertTag = 100; // declared at the top of your .m file, perhaps.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning"
message:#"Are you sure you want to delete this record?"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Delete", nil];
alert.tag = kDeleteAlertTag;
[alert show];
Then your delegate response might look like this:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == kDeleteAlertTag) {
if (buttonIndex != alertView.cancelButtonIndex) {
// code to delete record
}
}
else if (alertView.tag = kDoSomethingElseAlertTag) {
DoSomethingElse();
}
}

UIAlertView button to display viewController

I've been looking all over the internet for a solution to this problem, yet to find one that I can understand. So here it goes.
I have my iOS application, on which on the first launch of the application, will display a UIAlertView. I want one of the buttons to send the user to a new viewController to view some essential information.
I have gotten my UIAlertView configured properly, here's the code for the actionSheet:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
//Code to open a new viewController???
}
if (buttonIndex == 1)
{
//User can exit the application if they do not wish to continue
exit(0); }
}
}
I have a viewController created named webViewViewController, that's what I want users to reach when they tap the first button. Any ideas on how to do this? I have ARC disabled, other 'solutions' i've come across keep giving me errors.
Thanks all, would appreciate some guidance here.
If your current viewcontroller is in a Navigation Controller:
UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = #"My First View";
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
And never use exit(0)!
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
NewViewController *controller=[[NewViewController alloc]initWithNibName:#"NewViewController" bundle:nil];
self.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentViewController:controller animated:YES completion:nil];
}
drasick has given sufficient answer but if you need to use model view controller refer above.
Use:
UIViewController *yourViewController = [[UIViewController alloc] init];
[self.navigationController presentModalViewController:myViewController animated:YES];
to push a modalViewController.(This is depriciated in iOS 6, but will work)

How to show an alert before leaving the table view.?

I am working with a master detail application. In the master section records are listed, and detail section shows each record details. The detail section is a table view where we can edit each record. the problem is that "while editing a record,if i tap a record on the other side, any changes that i have made on the original record are lost and new record details are shown in the table view"...
can anyone please tell me how to show an alert that asks for "save or cancel" , before "showing the new record details"..
any changes that i have made on the original record are lost
A common rule in developing applications is
NEVER loose the user's work
So it would maybe just be the best idea to just save what the user changed.
But let's head to your actual question:
can anyone please tell me how to show an alert
I think you mean those alters looking like push notifications with two buttons.
You create them with UIAlertView.
Then in the alert's delegate you can figure out which button was pressed and you can decide how to go on. Just check out the documentation for UIAlertView - it's pretty simple :)
try this,
-(void)tableView:(UITableView *)tableView1 didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LString(#"ISCO_FLOW_CALC") message:LString(#"DELETE_MESSAGE") delegate:self cancelButtonTitle:LString(#"CANCEL") otherButtonTitles:LString(#"SAVE"), nil];
alert.tag=11;
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if(buttonIndex==1 && alertView.tag==11)
{
//your save data action;
}
if(buttonIndex==0 && alertView.tag==11)
{
//your Cancel data action;
}
}
Keep a reference to your DetailViewController in the MasterViewController
eg. in your MasterViewController.h:
DetailViewController *detailVC;
Set this reference to your most recent DetailViewController in didSelectRowAtIndexPath and always check if it is not nil before showing a new detailVC
DetailViewController *controller=[[DetailViewController alloc] init]; //Or similar
if (detail){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Save or Cancel" message:#"Save or Cancel" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save",nil];
[alert show];
}
else{
detailVC=controller;
//Show controller
}
Now show the new detailViewController after the user tapped a button of the UIAlertView:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex==0) { //Tapped cancel
//show detailVC
}
else{ //Tapped save
//save
//Show detailVC
}
}
Hope this helps

ModalViewController Without Dimming / Disabling current viewcontroller

I am displaying aNavController as a modalViewController in a specific frame CGRectMake(40,50, 400, 500). Which is working fine. Now I have a button in self (viewcontroller on which modalViewController is presented), on pressing that button I need to display some message on aNavController. But problem is when I am presenting a modalViewController. Whole screen area got dimmed/disabled. So, not able to touch/click that button in self.
Here is my code to present a view controller. I thought, I am missing something here. Please Help. Thanks in advance.
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aNavController animated:YES];
aNavController.view.superview.frame = CGRectMake(40,50, 400, 500);
presentModalViewController create a modal dialog. When modal view controller is up, users can't do any thing on parent view until the the modal view is dismissed.
The problem is you're instantiating a UIAlertView at the same time as the presentModalViewController call your modal view in UIAlertView's delegate method clickedButtonAtIndex.
Like so:
- (IBAction)clickedMyButton:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle: #"Title"
message: #"Message"
delegate:self
cancelButtonTitle:#"Close Button"
otherButtonTitles:#"Modal Button", #"Some Other Button", nil];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(#"User Selected Cancel");
}
else if (buttonIndex == 1) {
NSLog(#"Modal Button Clicked");
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aNavController animated:YES];
aNavController.view.superview.frame = CGRectMake(40,50, 400, 500);
}else {
NSLog(#"Some Other Button Clicked");
}
}
Or, if you wish for your UIAlertView to show on top of your navigation controller, ignore the above and simply wait to call your alert until the navigation controllers - (void)viewDidAppear:(BOOL)animated method.
In addition, I recommend you change your frame to stay within the bounds of the screen unless absolutely necessary. ex: CGRectMake(40, 50, 320, 480);
Finally, I am able to do workaround the things which work same way as a UIModalPresentationFormSheet.
I added the aNavController as a subview to the [[UIApplication sharedApplication] keyWindow] and which solves my all the problems.
Thank you all for your comments.

alertView:clickedButtonAtIndex: causes program closing

I have this piece of code which allocates 2 UIAlertView :
promptConnexion = [[UIAlertView alloc] initWithTitle:#"Connexion"
message:#"\n\n\n"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
promptConnexion.tag = 1;
promptInscription = [[UIAlertView alloc] initWithTitle:#"Inscription"
message:#"\n\n\n\n\n"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
promptInscription.tag = 2;
and this one which specifies what to do when buttons are pressed :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1)
{
if (buttonIndex == 1)
{
NSLog(#"Connexion button OK");
}
}
if (alertView.tag == 2)
{
if (buttonIndex == 1)
{
NSLog(#"Inscription button OK");
}
}
}
In my console I actually get "Connexion button OK" and "Inscription button OK" when I should to.
But right after my program is closing unexpectedly whithout any warning or error in my console.
Moreover, if I don't overload alertView:clickedButtonAtIndex: my UIAlertView is just closing, my app still runs correctly, but my buttons do nothing else (obviously).
I also wrote this code :
and showed my 2 UIAlertView this way :
[promptConnexion show];
[promptConnexion release];
and :
[promptInscription show];
[promptInscription release];
and overloaded alertView:didDismissWithButtonIndex: too :
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[alertView release];
}
What am I doing wrong?
Here is your problem;
[alertView release];
You don't want to be doing that at all. In fact if that is all you are doing inside the method, you can remove the method completely as well. This is causing a double release of the alert view which you have already released using [promptConnexion release] etc.
One way to detect such things is to run your program with NSZombiesEnabled as that can show you when you try to release an object that is already released.
This code is your problem:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex: (NSInteger)buttonIndex
{
[alertView release]; // Should not be released here!
}
The reason is, you have already released the alertView here:
[promptConnexion release];
[promptInscription release];
You have done your "duty" by releasing the object you have allocated. The alert view object is now under the responsibility of the operating system displaying that alert view, and it will release it when necessary, without any action of your part.
Just remove that code and it should work.
Also, you should read Apple's Memory Management Rules to have a better understanding of this issue
[promptInscription release]; and [promptConnexion release]; already releases the alertViews. You are releasing it and then after accessing the tag for those alert views and then release it again which I think is the reason for crash.
you should not release the alertView in
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
you already release the alertView instances so there is no need to release that..
Try with not release your alertView in below function.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex`
SO your function should be
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
//Put you code here
}
Just do one thing write your code as below
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1)
{
if (buttonIndex == 1)
{
NSLog(#"Connexion button OK");
}
}
if (alertView.tag == 2)
{
if (buttonIndex == 1)
{
NSLog(#"Inscription button OK");
}
}
}
No need to override clickedButton Index method just remove it