How to remove other UI components in ios - ios4

In my app i am having following scenario
There is thread running in background which check some flag is on or not
This thread is running for entire application.
If flag found "on" then go to some view (pushed from navigationcontroller)
So i need to discard or remove all other UI components like UIAlertView ,UIActionSheet etc
In my case when i pushed the view controller then actionsheet open is not discarded automatically
How can i remove all other UI Components already initiated whenever the view is pushed
Please do write to this thread
Thnx in advance
Parag Deshpande

-(void)removeSubView:(UIView view)
{
NSArray arr =view.subViews;
for(UIView* tmp in arr)
{
}

Related

WKWebview does not run javascript(XML HTTP request) with out adding a parent view

I am updating my project from UIWebView to WKWebView. In existing UIWebView approach where UIWebView does't have any parent until it runs javascript and once it has content, it adds a parent to the webview. Content renders fine using UIWebView. I am using the same approach for WKWebView, however WKWebview stuck at loading. Is there any way we can execute javascript on wkwebview without adding parent to the webview. Another interesting thing is it works on simulator not on device. Using localHTTPServer to serve the html, css and images.
Any Suggestions or Tips to solve the above issue.
I have observed similar behavior in my app running socket.io in a headless WKWebView. In my case, the web socket would disconnect all the time and not reconnect.
It seems that since WKWebView runs javascript off-process that it will pause any javascript that is considered idle to save resources (<-IMO). Idle includes not having a parent or the app/device is inactive. So, yes, it seems like you are correct in that it needs a parent view in most cases. I was able to work around this using the following code:
WKWebViewConfiguration* webViewConfig = // set up config
// provide empty frame rect
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfig];
// add to keyWindow to ensure it is 'active'
[UIApplication.sharedApplication.keyWindow addSubview:webView];
This approach at least ensures the javascript runs while the app is active and doesn't effect the UI. If you need to display it later you can remove the webView from the keyWindow after render and reset the frame. And, yes, I also observed that in the simulator this is not an issue (javascript ALWAYS runs, regardless of parent or app state)
Hope this helps!
The accepted solution worked for me some of the time. I tried something else which appears to work for me consistently:
self.keepWebViewActiveTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:#selector(_keepWKWebViewActive:)
userInfo:nil
repeats:YES];
Where _keepWKWebViewActive is:
-(void) _keepWKWebViewActive:(NSTimer*) timer{
if(self.webView) {
[self.webView evaluateJavaScript:#"1+1" completionHandler:nil];
}
}

MonoTouch: How to update a view [duplicate]

I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.
How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?
You could try something along the lines of:
//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);
//snip
void EnteredForeground (NSNotification notification)
{
// do your stuff here
}
Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!

Resetting ui: how?

I have an activity with a UI with many elements (Radio, EditText, etc.). When I change the text in an EditText I want that UI back at its starting state.
I tried to kill and restart the activity but with poor results. Any ideas?
Thanks
I would try calling setContentView again with a new view or with the xml file you used for rendering your activity in the first place
Once you get the value you need from your editText, you can reset it using
editText.setText("");
You can similarly programatically control other parts of your UI too.
Why not put all of the reset stuff in one function and simply call it when you need to:
public void resetUI()
{
//reset UI programatically
}
You could add a listener to the EditText view and when the text is what you want it to be you can just programmatically empty any TextView's, EditText's, reset any radiobuttons or radio groups to their default values. No need to restart the activity. Just write a helper method that resets your view "manually". Using setContentView() could also work although I haven't tried it and you might have to setup your complete view again with listeners and such.

Creating UIElements outside Ui thread, Silverlight

In my silverlight 4.0 application, at one point, after user pushes a button, I have to create few UI objects that take some time (5-10seconds). During this time UI freezes of course. I decided to put creation of those objects in a background worker so UI could at least show progress bar.
But this solution does not work. To create UI object you have to be in UI thread.
If I put creation of those object inside Dispatcher.BeginInvoke() than again my UI freezes. In most cases without even showing progress bar. Is there a way around this?
Can I show progress bar while silverlight creates UI objects in the background?
Have a look at this forum post. It may help.
Instead of using:
System.Windows.Threading.Dispatcher.BeginInvoke(() => {});
They use:
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {});
You can try displaying a custom message before creating UI objects inside BeginInvoke().
Example:
private void CreateObjects()
{
myMsg.Text = "Loading...";
Dispatcher.BeginInvoke(() => { AddObjects() });
}
Once all objects are created, disable the message.
You can try the similar thing with Progress Bar also.

How do i refresh a tableview after returning from Background

How do I refresh a tableview after returning from Background(when the user hit home button and comes back later). Its not calling the viewWillApper delegate method.
Thanks,
Shinto.
Override applicationDidBecomeActive or applicationWillEnterForeground in the appDelegate. Then I would either call the table view controller to reload or use a NSNotification.
Note: applicationDidBecomeActive is also called when the app launches. See: Understanding iOS 4 Backgrounding and Delegate Messaging
u can do it in the Home Button. First Get the ViewController thats hold the TableView and do further action...

Resources