iPhone UIAlertview abandon memory - ios

I use UIAlertview to input some text, and it works fine.
However, after the alertview is closed, there is still more than 17MB increase in memory before alertview is opened(from 9MB to 26 MB). I used Instrument Allocation to measure heap memory and activity monitor to measure it. Both of them show the similar result. When I switch to other App, the memory increased by alertview will be reduced to the proper level. Is it normal ? My environment is iPhone4+iOS6.
Here's some code for trying.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"input caption" message:#"text"
delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
Thank you.
Dear Naveed S and Purr,
Thank you very much.
I'm not sure I follow your suggestion correctly. But I use Activity monitor watch the Real mem, the memory still increase about 20 MB after alertview is closed. I remove [alert release] after [alert show], and I wrote
[alert show];
//[alert release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
[alertView autorelease]; }
Moreovre, the memory is reduced when the app enter background mode after I press home. (This is similar as my previous code). How could I watch the abandon memory correctly. I'm even not sure how to watch it in the right way.....
BTW, my original codes follow the post here. Uialertview and memory management

For one thing, you should autorelease your alertView. -alertView:didDismissWithButtonIndex: is called by the UIAlertView, so the alertView object should still be valid (not -release'd) when your method returns.
Better yet, convert to ARC and be done with manual -retain, -release and -autorelease ;)
If you're not converting to ARC, do this: remove the -release from the code in your original post, uncomment the //CRASH in your -alertView:didDismissWithButtonIndex: method and change the -release to -autorelease there.

Related

Alert message not rotating in IOS8

I am building an iPhone app which shows an alert message when a particular button is tapped. Auto-rotaion is in ON state. When i rotate my phone the whole app view as well as the alert message rotates in iOS7 But, in iOS8 views are rotated except alert message`
UIAlertView does not work properly in iOS8 The, iOS8 uses a new UIAlertController The given linked worked for my case.
Reference Link
This is happening because the iOS not able to understand the multiple operation at a time .You can call the UIalertview with delay like .I have same issue with iOS8 this code is working fine for me.
[self performSelector:#selector(showAlert) withObject:nil afterDelay:0.5];
-(void)showAlert
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Your alert Title." message:#"Your alert Message." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}

Let the UIAccessibilityPostNotification complete in UIAlertView

I want to announce a message through UIAccessibilityPostNotification in a UIAlertView. My problem is that the alert view closes and the message abruptly stops (at least that is my analysis), barely two words get spoken. Is there any way to let the notification complete? My code is as follows:
//Function which calls UIAlertView
-(IBAction)foo:(id)sender
{
UIAlertView* myAlert = [[UIAlertView alloc] initWithTitle:#"Select to get more information"
message:#""
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"a",#"b",#"c", nil];
myAlert.tag=2;
[myAlert show];
//Code comes here immediately, even if I don't select anything on alertView.
NSLog(#"Does it come here? Yes!");
}
My AlertView:
if ([alertView tag]==2)
{
//Some code
NSString* message = #"Long message";
if (UIAccessibilityIsVoiceOverRunning())
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, message);
else
NSLog(#"Voice-over is not running.");
}
I am also ready to change my code logic. I tried if the code continues after we select a choice on alert view, so that I can make the message variable global and post the notification through the foo function. It doesn't happen as expected. Program stops after alertView closes.
Does any workaround exist? I am an amateur iOS programmer so a little code along with the explanation would help.
P.S. I can even use something other than alert view, if there is any. I just want to have a pop-up and some buttons as choices.
IMO, you should create your on Custom popup using UIView to display options to the end user. Then first display your popup that gives user the options, once user selected one of them (or tap a button after selecting one of them), call UIAlertView to show the relevant messages.
Hope this way your problem will be solved.

How to position a UIAlertView

I've tried using this
message = [[UIAlertView alloc] initWithTitle:#"Incorrect!"
message:wrongString
delegate:self
cancelButtonTitle:#"Try Again"
otherButtonTitles:nil];
if(adjustIncorrect) {
NSLog(#"Showing adjusted");
message.transform = CGAffineTransformMakeTranslation( 0.00, 300.00);
}
[message show];
It is printing out Showing Adjusted, so I know that's not the issue. But the alert isn't moving no matter what numbers I put in. I've seen a few posts saying with the newer versions of iOs this might not work, any ideas?
Unfortunately you can't do it: "The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.". You should not access any private properties in UIAlertView directly as well as you should not subclass UIAlertView - this is clearly stated by Apple and is likely to lead to a rejection of your App during revision when sent for publication to the Apple Store. The same applies to UIActionSheet.
Instead you should look into implementing your own alert view to be loaded modally when needed.

App goes straight to idle on setIdleTimerDisabled: NO

I'm using
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
to keep the app from entering idle, however when I issue
[[UIApplication sharedApplication] setIdleTimerDisabled: NO];
the app goes straight to idle.
Is there a way to restart the timer at this point?
No there is no way to restart the timer. Perhaps you should consider if your app really needs to do this.
Quote from Apple:
"The only applications that should disable the idle timer are mapping
applications, games, or similar programs with sporadic user
interaction."
If you app does need to turn the idleTimer off then perhaps it can stay off till the app goes in to the background?
You could try adding an alert at the end of the timed event
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"Timer Complete" message:#"Timer ended, well don you" delegate:nil cancelButtonTitle:#"OKAY" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
Omit the release if you're using ARC. This may light the screen backup, then perhaps you don't need to mess with the idle timer.
This is obviously too late for the person who asked this question, but for anyone else who is looking, what has worked for me is to do this:
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
Including all three lines one after the other somehow resets the timer. So the timer won't dim upon immediately receiving setIdleTimerDisabled:NO but rather will take a while before it dims.

'wait_fences: failed to receive reply: 10004003' on loading UIAlertView (iOS)

I'm getting the 'wait_fences: failed to receive reply: 10004003' when I call a UIAlertView. It's called when the app first opens. It doesn't crash the app or seem to effect the functionality of it at all but I want to clean up my app completely. It's a tab bar app and I've entered the code in the viewDidLoad section of the View Controller that's first loading in the app:
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Welcome!" message:#"Thanks for downloading our new app! \n \n Take a look around and if you have any questions, don't hesitate to contact us." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
I have seen other answers on the site to this error but they seem to deal with UITextFields and I'm not sure how they apply to my situation exactly. I apologize if I'm missing something simple, but I'm learning hands-on and can't seem to figure this one out. Thanks!
You should show it in -(void)viewDidAppear method. When view just loaded it is not on screen.

Resources