I am created an app, after login have to download new database from web and when you logged
in a custom UIAlertView appears if user press yes the download phase will be started. When
the UIAlertView disappear and the UIAlertView's delegate called i start on the background
thread a download. Now i am trying to modify a label which display the current percent and
adding to the view a custom activity indicator. After that when the activity indicator
changing the pictures or the label.text get a new string the screen start flickering, but
only at the very first start (after install), if i force close the app and starting it
again the flicker thing is not appearing, on previous version of iOS the app not flicker. I
am calling from main thread when i modify the label. I tried remove label and activity
indicator and after the alert view disappearing the app not flicker. I tried to remove
alert view and start instantly the download and after that only the status bar started to
flicker.
So my question: what should i do to solve the flicker bug?
I believe that the reason is because you are updating the UI on a background thread. You must not do this, you must use the main thread for this:
To run code on the main thread from the background thread, you can use GCD:
dispatch_async(dispatch_get_main_queue(), ^{
//your UI code here
});
If this doesn't fix the error, it's probably a bug with your device.
Related
Currently I encounter an issue somehow, the application lost all those artistic UI animation for example, page flipping, alert view popup, action sheet slide up and etc. That means all those UI will show up immediately without any transition animation. It looked very weird.
Firstly, the app will run smoothly until something trigger the issue above, and after that only re-run the app or kill the app will stop the problem.
There is no error message or any clue that I can figure out what could be the reason. Have any one of you guy has encountered similar issue as above? Please share with me how am I able to solve the issue above. Thanks.
Animations may get disabled for the entire app whenever an attempt is made to animate views on a background thread, e.g. by calling one of UIView's animateWithDuration:animations: family of class methods from a background thread. Be sure to update your app's UI only from the main thread.
You can check if code is running on the main thread by testing [NSThread currentThread].isMainThread and you can ensure it runs on the main thread like so:
dispatch_async(dispatch_get_main_queue(), ^(void) {
// Your code
});
Alternatively, ensure that you're not calling [UIView setAnimationsEnabled:NO] anywhere, as that will also disable animations for the entire app.
I load image by NSOparationInvokation and call out method in the main thread, which adds this image to scroll view, but app hardly lags. If I load image but not add it view, app works normally, if I add test button on view app also work normally and if I load image and add test button to view app don't lag. By profiler problem in __spin_lock. Someone knows what's wrong?
Thanks.
When using threads on iOS, you should never ever ever make calls to UIKit. That's why it won't load. Put it on the main thread and it'll work.
I've made a custom activity indicator (actually just an imageView)
When user clicks something and I expect it will take a bit long to process(alloc a UIViewController and push on to navigation stack),
I alloc the indicator and add it as subview of current view just before the lengthy process starts.
Strange thing is, indicator doesn't show up until the push (left-right) animation starts.
Is it because the lengthy job takes the system, and ui drawing for activity indicator is delayed?
Am I doing something wrong here?
Thank you
Edit
Looks like I can do the "push" in background.. i'm trying it now
IPhone SDK - Leaking Memory with performSelectorInBackground
Is your job synchrone or asynchrone ?
If it's the first case, then it can be the problem.
Check all the method like :
[ self performSelector:<#(SEL)aSelector#> ];
You can thread this to avoid your [potential] problem.
Good luck.
You should process your lengthy tasks in the background. The UI won't update if you block the main thread.
So you have to refactor your app, the alloc and push of the viewController should happen within the blink of an eye, because you can't do this in the background.
But you can do the processing (downloading data I guess) in the background.
There is plenty information available about background processing. The way to go varies heavily on what you want to do exactly.
I am developing an iPhone application (iPhone with multi tasking support) in which I am displaying UIAlertView on error. When UIAlertView is about to get display my app is sent to background. Now, if I try to get my app in the foreground, UIAlertView gets displayed for a moment and gets dismissed automatically even if I don't call dismiss/click on any button.
Does anyone knows what the problem is?
Thanks and Regards,
Deepa
When you add an alert view, it is added on top of the view of the current viewcontroller and while coming back to foreground , sometimes the view is reloaded from the xib and all the contents are refreshed. I suggest you to maintain a state variable in controller which calls the alertView again when coming back to foreground.
Rajact answer is good if by 'call' means the next
[theViewWhenYouAddedIt bringSubviewToFront:theViewWhenYouAddedIt.theAlert];
This worked for me
I hope this helps someone
I am experiencing an issue with activity indicator freezing when I move application to background and then bring it back to foreground. The application can be loading some data over the network when it is moved to background. Hence I display an activity indicator to the user. I have added the code to make sure that the task finishes in the background.
When the application is brought to foreground immediately and the data is not completely loaded, the spinner stays on the screen but it stops spinning. When the data is completely loaded, the spinner disappears.
Any idea why the activity indicator freezes and what could be a possible solution to it.
Thanks.
There's almost no reason for an app in the background to be updating its UI.
For one, who is there to see it? Another reason that the indicator freezes is that going to the background stops UI updates and animations that needlessly drain the device's battery and slow down the foreground app.
From Apple's excellent iPhone Application Programming Guide, the app delegate method -applicationWillEnterForeground: is called whenever the application comes into foreground.
You can override this method and add logic to wake up widgets here. Or you subscribe your class (view controller, etc.) to listen for the UIApplicationWillEnterForegroundNotification notification. If you listen for this notification, you could call a selector that updates the state of the UI, given whatever the application is doing at the time.