**bool _WebTryThreadLock(bool),** 0x4c7a7e0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
I m getting an above error when i do this,
[alertForSavingText dismissWithClickedButtonIndex:ALERT_CANCEL animated:YES];
This is my custom alert with textField inside. Error comes only when I switch the application from background to foreground also it occurs when there is some text present in custom alert textField & keyboard is also visible.
Any suggestion.
Please check whether the current thread is main thread. If it is main thread, dismiss it as you have given. Else, if it is secondary thread, dismiss the alert view in main thread by calling performSelectorInMainThread:... method
Related
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.
I am trying to show and hide three controls like UIBUtton, UILabel etc. in some scenario. I am doing this using below two functions.
- (void) hide
{
usernameField.hidden=YES;
passwordField.hidden=YES;
myLabel.hidden=YES;
}
- (void) show
{
usernameFieldField.hidden=NO;
passwordField.hidden=NO;
myLabel.hidden=NO;
}
But, when i call these functions under some server response code, that is i'm trying to show under connectionDidFinishLoading in success/failure server response..Its not doing that. i.e. Its not showing or hiding these controls in these situations..But same time, if i call these functions under a button click, its showing/hiding controls..So, Would these functions be called only under some events like button click? Can't we call from anywhere like i'm trying to do?
Please advise!
in your connectionDidFinishLoading
[self performSelectorOnMainThread:#selector(show)
withObject:nil
waitUntilDone:wait];
the reason is UI update show be called on main thread in order to get redraw.
Changing the hidden state of a control will not immediately draw the change to the screen, they will only flag it as needing to be drawn at some point in the future.
If the main thread is busy, then they will not get a chance to draw themselves.
Is your NSURLConnection code running on the main thread? You should move it to a background thread (but beware, changing the hidden property must be done on the main thread, not on a background thread! Look up grand central dispatch.)
In my app, I have a UITableViewController which loads calculated data from my Core Data store. This can take quite some time and hangs the main thread, so to give the user visual feedback, I have installed the MBProgressHUD widget which will show a progress indicator (just the spinning wheel) while the calculation method runs in a separate thread.
This is fine, except that the user can still exit the UITableViewController if they think it's taking too long. Of course, this is a good thing, except that when the separate thread concludes its operation, it still tries to call its delegate (the UITableViewController) to hide the MBProgressHUD. This causes a crash because since the user already exited the UITableViewController, it has dealloc'd and release'd itself.
MBProgressHUD has the following code to try to stop this:
if(delegate != nil && [delegate conformsToProtocol:#protocol(MBProgressHUDDelegate)]) {
if([delegate respondsToSelector:#selector(hudWasHidden)]) {
[delegate performSelector:#selector(hudWasHidden)];
}
}
However, my app somehow seems to still be running this inner code ([delegate performSelector:#selector(hudWasHidden)]) even though the UITableViewController is totally gone--causing the app to crash.
Any suggestions? I am not running with NSZombiesEnabled.
From your UITableViewController viewWillDisappear, viewDidDisappear or dealloc method, set the MBProgressHUD.delegate = nil;
Once the user has exited the table controller, the delegate property of the hud points to a deallocated object (= a memory zone that could contain anything). That causes the crash when the computing thread ends and tries to send any message to the delegate.
In your table view controller dealloc, you must set the hud delegate to nil.
I have a main and an auxiliary thread in my app. Main thread as everyone knows is being used by UI. I use the secondary thread to do the background loading of my views.
I have a main controller which i call a dummy controller. From there i call my main controller, which is in landscape mode.
So basically what i have to do is, when i rotate my dummy controller, i want to be able to load my main landscape controller and vice versa.
Everything works fine when i rotate from dummy to main.
The main has a series of child controllers to load, so i have put up that process on a secondary thread, and by that time they are loading i show a loader screen.
The dummy is a normal view controller, and the main is a modal view controller.
Now the problem.
if a user is trying to rotate form dummy --> main, the rotate method kicks of the initialisation of the main view controller. But for some reason the user changes his mind and rotates back form main-->dummy ideally, the transition should be smooth as the UI thread(main theread) is free. What happens is the UI rotates back. But since the secondary thread on the Main controller is still on, even after the dismiss modal controller is called on the MainController by the main thread, when we call the willRotate function.
I've read in various post that we cannot simply kill the secondary thread, as we have to do clean up stuff ourselves. So can anyone please guide me through code, how do i kill my secondary thread and do clean up before i transit back to my calling form..??
Its kinda urgent... please dont point to other thread topics, cos i've already visited those.
I specifically want to know how should i stop my secondary thread, without causing a crash.
thanks.
-(void)viewDidLoad {
[super viewDidLoad];
workingThread = [[NSThread alloc]initWithTarget:self selector:#selector(parseMainTextFile) object:nil];
[workingThread start];
[NSThread detachNewThreadSelector:#selector(addLoader) toTarget:self withObject:nil];
//[self performSelectorOnMainThread:#selector(parseMainMatchTextFile) withObject:nil waitUntilDone:NO];
}
Generally saying, if you run a background thread it means you've got a Run Loop, which works in a while statement. You should have a flag which stops the Run Loop. this way it would transform the state of the thread to finished.
while (mRunLoop && [mLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
This is the way I do. Additionally read this Post and its sub posts from comments. Good luck!
So I am trying to create a check that tries to connect to the WWW. when it fails it needs to then retry several times before the application gives up and quits. Each time it retries the user is propted with an UIAlertView with the options to Retry or Cancel.
So here is the problem.
I have a chain of actions in an NSOperationQueue, all the operations should fail with no connection. I"m using the NSoperation Queue so that the UI dosn't lock and the data is being processed in the background.
inside an NSInvocationOperation my method will hit [AlertView show], however this is not truly modal.
My operation then returns and continues through the chain of NSOperations, as there seems to be no way to return them with an Error value to stop additional processing. Eventually the UI catches up, displays the Modal AlertView, but i have no context of what has happened.
I am sure this is a common requirement. any ideas how to achieve this?
If I understand you correctly, you want a modal version of UIAlertView, but only modal within the calling thread/NSOperation? A few problems with this:
You should probably only call interface operations from the main thread (easily addressed using performSelectorOnMainThread:)
Modal dialogs are not really part of the OS; you'll need to address this programatically.