How to allow UITapGestureRecognizer to detect taps on web view? - iphone

I have made web browser for iPhone in Xcode, and to exit the web browser and go back to the main page you tap on the screen three times, except that the gesture will only work on the toolbars at the top and bottom of the screen but not on the web view.
What can I do?
Here is my code
.h File
#import <UIKit/UIKit.h>
#interface Internet : UIViewController {
IBOutlet UIWebView *webview;
IBOutlet UIBarButtonItem *forwards;
IBOutlet UIBarButtonItem *backwards;
IBOutlet UITextField *URLTextField;
}
- (IBAction)share:(id)sender;
- (IBAction)returnKeyPressed:(id)sender;
- (IBAction)google:(id)sender;
- (IBAction)reload:(id)sender;
- (IBAction)forwardsButton:(id)sender;
- (IBAction)backwardsButton:(id)sender;
#end
.m File (only relevant code shown)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *homePageString = #"http://www.google.com";
NSURL *homePage = [NSURL URLWithString:homePageString];
NSURLRequest *requestHomePage = [NSURLRequest requestWithURL:homePage];
[webview loadRequest:requestHomePage];
forwards.enabled = NO;
backwards.enabled = NO;
UIAlertView *touchHelp = [[UIAlertView alloc] initWithTitle:#"Alert, Please Read" message:#"To go back to the App Selection Page please anywhere on the top or bottom toolbar three times" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[touchHelp show];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapRecognizer.numberOfTapsRequired = 3;
[self.view addGestureRecognizer:tapRecognizer];
}
- (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer {
[self dismissViewControllerAnimated:YES completion:nil];
}

Implement shouldRecognizeSimultaneouslyWithGestureRecognizer delegate and return YES.
Implementation details:
Add the UIGestureRecognizerDelegate protocol to your .h file
#interface ViewController : UIViewController <UIGestureRecognizerDelegate>
Add this delegate in your .m file
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES
}

Related

Why is my web view fail delegate not working?

.h
IBOutlet UIWebView *webview;
.m
- (void)viewDidLoad {
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://blabla.com"]]];
}
- (void)webView:(UIWebView *)webViewfail didFailLoadWithError:(NSError *)error {
if([webViewfail isEqual:webview]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Connection Failed"
message:#"Check your Internet connection before refreshing."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
I do not know what I did wrong, I tried making it appear but setting off internet connection. Any tips or suggestions will be helpful.
Make sure you have hooked up the delegate in interface builder (if that is what you are using). You can do this by selecting the web view, and drag (while holding control) to the view controller / file's owner, and then select delegate (which pops up when you release the mouse).
Or you can hook up your delegate in code in your viewDidLoad method like so:
[webView setDelegate:self]
Make sure your view controller conforms to the UIWebViewDelegate protocol by adding in your .h
#interface MyViewController : UIViewController <UIWebViewDelegate>
Good luck :)
Check this:
Make sure the object containing the quoted method is indeed the web view's delegate.
Give the web view's url request a really short timeoutInterval.
Try this also:
In your ViewController.h
#interface ViewController : UIViewController <UIWebViewDelegate>
And in ViewController.m below [super viewDidLoad] add :
self.webView.Delegate = self;

Frustrating UIWebView Delegate Crash issue

I've created an ARC Application that run's perfect. It's got a UINavigationController that I use to push through the views and everything runs fine.
I'm converting the Application to iPad and i've decided to show one of the views as a popover. (I don't like UIPopoverController so i've created my own basic popup). It's added to the view as follows..
MyViewController *hotelinf = [[MyViewController alloc]
initWithNibName:#"MyViewController_iPad" bundle:nil];
[self.view addSubview:hotelinf.view];
The view is added as a subview fine. The view i'm adding contains a UIWebView that has the usual delegate methods in it, but when the view tries to access one of the delegates it simply crashes.
*** -[MyViewController respondsToSelector:]: message sent to deallocated instance 0x7917b90
Specifically, it crashes on this line..
[self.webView loadHTMLString:stringResponse baseURL:nil];
I've displayed views (and UINavigationControllers) as subViews many of times without any issues, although none of them included a UIWebView delegate. I'm guessing I have to set the delegate of my UIViewController istance but i'm not sure how. It's also worth noting that if I push the view in my existing UINavigationController it calls and loads the HTML fine, which surely means it has nothing to do with the code of the view itself.
Any help would be greatly appreciated! Here is the code (in addition to above that shows the controller)..
.h
#interface MyViewController : UIViewController <UIWebViewDelegate, UIActionSheetDelegate> {
//Unrelated IBOutlets
}
#property (nonatomic, strong) UIWebView *webView;
#end
.m
#implementation MyViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(317,283,393,354)];
self.webView.delegate = self;
[self.view addSubview:self.webView];
[NSThread detachNewThreadSelector:#selector(getHTMLString) toTarget:self withObject:nil];
}
-(void)getHTMLString {
#autoreleasepool {
//Download a valid HTML String
[self performSelectorOnMainThread:#selector(loadHTML) withObject:nil waitUntilDone:NO];
}
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.webView = nil;
}
-(void)loadHTML {
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
if ([stringResponse isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Could not connect to XXXXX.com. Please verify you are connected to a working 3G/WIFI Network." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
} else {
//it crashes here only when loaded as a subview - the first access to the delegate
[self.webView loadHTMLString:stringResponse baseURL:nil];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self stopIndicator];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
if (error.code == NSURLErrorCancelled) return; // this is Error -999
[self stopIndicator];
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
#"<html><center><font size=+10 color='black' face='Helvetica'>An error occurred:<br>%#</font></center></html>",
error.localizedDescription];
[self.webView loadHTMLString:errorString baseURL:nil];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Cannot load URL."
message:#"You have a connection failure. Please verify you are connected to a WIFI or 3G enabled Network."
delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}
#end
The issue has nothing to do with the UIWebView, rather with your controller class. Indeed,
MyViewController *hotelinf = [[MyViewController alloc]
initWithNibName:#"MyViewController_iPad" bundle:nil];
[self.view addSubview:hotelinf.view];
You are allocating the controller and assigning it to a local variable; then you add the controller's view as subview to your current view. Doing that, that view is retained, but what happens to the controller object itself? Are you releasing it? Or it leaks (since it is assigned to a local variable)?
This possibly explains why when later the respondsToSelector method is called, the controller has already been deallocated...
A way to fix this is creating a new property or an ivar in your main controller class and store MyViewController in there. Don't forget to release it in dealloc.
I would also suggest another thing. In:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.webView = nil;
}
set the webView delegate to nil before releasing the view:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.webView.delegate = nil;
self.webView = nil;
}
And I would also possibly review the reason why you release the webView in viewDidDisappear. On the other hand you allocate it in viewDidLoad. This asymmetry is dangerous, since whenever the main view disappears (for any reason) the webView will be removed and when the view reappears, it is not there anymore.
Better add all the delegate methods. You havent added the first two. Most probably, your code is crashing when message webViewDidStartLoad is sent
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
– webView:didFailLoadWithError:

How to create new view w/ webview from push of button

UPDATED QUESTION:
Hello , so I was able to create the modal view curl up overlay for this use. However I now have the issue that I can click on the button1 and pull up second view with the url1 on webView1, but when I click button2 I receive the display of url1 on webview also. below is the code can you help me out on what I'm doing wrong?
FourthViewController.h has the following code:
'
#import <UIKit/UIKit.h>
#interface FourthViewController : UIViewController {
UIButton *openBlogButton, *openFbButton, *openYelpButton;
}
#property (nonatomic, retain) IBOutlet UIButton *openBlogButton, *openFbButton, *openYelpButton;
-(IBAction)openBlog:(id)sender;
-(IBAction)openFacebook:(id)sender;
-(IBAction)openYelp:(id)sender;
#end
'
FourthViewController.m has the following code:
'
#import "FourthViewController.h"
#import "FourthBlogWebViewController.h"
#import "FourthFBWebViewController.h"
#implementation FourthViewController
#synthesize openBlogButton, openFbButton, openYelpButton;
-(IBAction)openBlog:(id)sender {
FourthBlogWebViewController *sampleView = [[[FourthBlogWebViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
//THIS IS WHERE I THINK THE ISSUE IS, WHEN I CLICK openFacebook it should lead to the fb URL, it seems as if I should be able to list all possible urls on the first fourthwebviewcontroller, but i was not able to be successful so I tried making a second webview controller to feed it this url but this failed...lol. thnx for any input.
-(IBAction)openFacebook:(id)sender {
FourthFBWebViewController *sampleView = [[[FourthFBWebViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
-(IBAction)openYelp {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.yelp.com"]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[openBlogButton release];
[openFbButton release];
[openYelpButton release];
[super dealloc];
}
#end
'
FourthBlogWevViewController.h
'
#import <UIKit/UIKit.h>
#interface FourthBlogWebViewController : UIViewController {
UIButton *dismissViewButton;
IBOutlet UIWebView *webViewFB;
}
#property (nonatomic, retain) IBOutlet UIButton *dismissViewButton;
#property (nonatomic, retain) UIWebView *webViewFB;
- (IBAction)dismissView:(id)sender;
#end'
FourthBlogWebViewController.m code:
'#import "FourthBlogWebViewController.h"
#implementation FourthBlogWebViewController
#synthesize dismissViewButton, webViewFB;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
return self;
}
-(IBAction)dismissView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.facebook.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webViewFB loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[dismissViewButton release];
[webViewFB release];
[super dealloc];
}
#end
Where or how would I add the second url and have it distinguis on click of other buttons. Thank you in advance for the ongoing help.
Original Question:
Hello,
So first app and I'm trying to make some basic function use of buttons, Im doing this in a tab bar application. On my fourth tab view a view opens with 3 buttons, on the click of the button I am trying to get a webpage to load within the app (i was able to successfully make the webpages open via safari on button touchup inside click, but that is not how I want it to load. So I edited the way it loads and on push of button the website is now opening within the webView. However I want to create this webview on a new view rather then on the same view where the 3 buttons are, but I'm not clear on how to do this. Any input would be greatly appreciated (I apologize beforehand since this seems as an easy task, but haven't figured it out yet, I did some searching before asking, but was unable to find anything that showed how to do this on push of different button to load webview on a new view within the same XIB.
Thanks.
Below is the code that I have for the load of webview on push of button.
On fourthviewcontroller.h
#import <UIKit/UIKit.h>
#interface FourthViewController : UIViewController {
IBOutlet UIWebView *webView;
}
-(IBAction)openWebsite:(id)sender;
-(IBAction)openButton2;
-(IBAction)openButton3;
#property (nonatomic, retain) UIWebView *webView;
#end
On fourthviewcontroller.m
#import "FourthViewController.h"
#implementation FourthViewController
#synthesize webView;
-(IBAction)openWebsite:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.URL.com"]]];
}
-(IBAction)openButton2:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.URL2.com"]]];
}
-(IBAction)openButton3:(id)sender{
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.URL3.com"]]];
}
Basically I'm trying to get different buttons to push to the same new view but the only difference is that i want the uiwebview to display a different URL depending on the button click that bring the new view.
As NWCoder mention, it depends how you like the new webview to be shown.
Display in UINavigationController-
Make your fourth tab a uinavigationcontroller and set the 3 button view controller as the top most view controller.
Create a new UIViewController that encapsulate the UIWebView.
When user click on the open webview button, create and push the uiviewcontroller that contains the uiwebview
Display in modal view:
Create a new UIViewController that encapsulate the UIWebView.
When user click on the open webview button, create and push the webview uiviewcontroller by calling the fourth's tab uiviewcontroller presentModalViewController:animated.

insertSubview: AtIndex: does not work

I went through the material regarding this issue but still can't figure it out completely.
The main issue is that i am using this method but the view does not show...
The app is built out of two view - the main one (i added it as a subview to the main nib) -
Has of a text field where i write some text.
Has a button that when pressed, the action method loads a second view that has a label with some text in it.
the source code of the first viewController:
#import <UIKit/UIKit.h>
#class TxtRunnerViewController;
#interface Itai_s_text_app_take_2ViewController : UIViewController {
int sliderSpeed;
IBOutlet UITextField *textInput;
TxtRunnerViewController *trvc;
}
#property (nonatomic, retain) IBOutlet UITextField *textInput;
#property (retain, nonatomic) TxtRunnerViewController *trvc;
- (IBAction)sliderChanged:(id)sender;//speed of text show changed
- (IBAction)textFieldDoneEditing:(id)sender;//dor 'DONE' on keyboard
- (IBAction)backgroundTap:(id)sender;//for handling tapping on background
- (IBAction)textEmButtonPressed:(id)sender;
#end
the .m of the first ViewController:
#import "Itai_s_text_app_take_2ViewController.h"
#import "TxtRunnerViewController.h"
#implementation Itai_s_text_app_take_2ViewController
#synthesize textInput;
#synthesize trvc;
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
sliderSpeed = (int)(slider.value + 0.5f);//setting the speed determinned by the usr in slider
NSLog(#"Slider value is %#", sliderSpeed);
}
- (IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
NSLog(#"our text input is %#", textInput.text);
}
- (IBAction)backgroundTap:(id)sender
{
[textInput resignFirstResponder];
}
- (IBAction)textEmButtonPressed:(id)sender
{
NSLog(#"button pressed");
if ([textInput.text length]==0)
{
NSString *msg = nil;
msg = #"Write text to transmit";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Forgot something?"
message:msg
delegate:self
cancelButtonTitle:#"Back"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
else { //init
NSLog(#"HI!");
if (self.trvc == nil)
{
NSLog(#"if accepted");
TxtRunnerViewController *tr = [[TxtRunnerViewController alloc] initWithNibName:#"TxtRunner"
bundle:nil];
self.trvc = tr;
[tr release];
}
[self.view removeFromSuperview];
[self.view insertSubview:trvc.view atIndex:0];
NSLog(#"InsertAtIndex was operated...!");
//[self.view addSubview:tvc.view];
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
if(self.trvc.view.superview == nil)
self.trvc = nil;
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[trvc release];
[super dealloc];
}
The second View is simply empty (has a label added to it in it's nib file):
#import
#interface TxtRunnerViewController : UIViewController {
}
#end
It's .m file is the default one, added no code to it.
When i press the button in the first view - it's view disappears but the second view does not appear instead, only a blank white view appears, nothing on it.
Doe
If you push the TxtRunnerViewController it will completely hide the first one, but it still exist in background. (without removeFromSuperview)
TxtRunnerViewController *vw = [[TxtRunnerViewController alloc]initWithNibName:#"TxtRunner" bundle:nil];
[self.view pushViewController:vw.view animated:NO];
[vw release];
To remove the first view it's a bit more difficult. You would need to implement a delegate in RootViewController which will be fired after clicking the done Button of the first view. Then in your RootViewController some code is executed which displays the second view and removes the first view.
For a delegate sample open the Utility Application Sample when creating a new project and figure out how it works or search some examples online.
The line:
[self.view removeFromSuperview];
Removes the view from its super
then the call
[self.view insertSubview:trvc.view atIndex:0];
Adds trvc to it - but that view has been removed and not visible anymore.
You need to add trvc to the superview.

View loaded from nib will not update contents of UILabel while running in a method

I am having an issue with updating the contents of an "myInfoBox" object I created to be displayed while some background processes are done.
In the delegate method I am creating a new viewController:
-(void)loadMainView
{
myFirstViewController = [[MyFirstViewController alloc] initWithNibName:#"MyFirstView" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
// myFirstViewController was retained again by the controller, release one
[myFirstViewController release];
navigationController.navigationBar.hidden = YES;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
// the next method is run after the "viewDidLoad" is finished loading
[myFirstViewController loadAlertViewForNewUser];
}
Following is my implementation of "myFirstViewController", it creates an instance of the "infoBox" class(I will show its code later):
- (void)viewDidLoad {
self.navigationController.navigationBar.frame = CGRectMake(0, 0, 0, 0);
self.navigationController.navigationBar.bounds = CGRectMake(0, 0, 0, 0);
self.myInfoBox = [[InfoBoxController alloc] initWithNibName:#"InfoBox" bundle:[NSBundle mainBundle]];
CGRect infoBoxFrame;
infoBoxFrame = CGRectMake(60, 120, 200, 200);
myInfoBox.view.frame = infoBoxFrame;
myInfoBox.i_statusLabel.text = #"Downloading Account Updates";
myInfoBox.i_titleLabel.text = #"Updating";
// disabled for testing
//myInfoBox.view.hidden = YES;
[self.view addSubview:myInfoBox.view];
[super viewDidLoad];
}
// this method is called after the view has been loaded by the delegate
- (void)loadAlertViewForNewUser
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome!" message:#"Connect to download stuff from your account?"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
alert.tag = 0;
[alert show];
}
// implementation of the alertview delegate
- (void)alertView:(UIAlertView *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == 0)
{
if (buttonIndex == 0)
{ NSLog(#"button 0 was pressed"); }
if (buttonIndex == 1)
{
// this is the button that is pressed
[actionSheet removeFromSuperview];
[actionSheet release];
// tried using this also
//[self performSelectorOnMainThread:#selector(userInitialSetupMainThread) withObject:nil waitUntilDone:NO];
// do stuff and update the infobox about it
[self loadInfoBoxInitialUserSetup];
// tried using this as well
//[self performSelectorInBackground:#selector(loadInfoBoxInitialUserSetup) withObject:nil];
}
return;
}
}
- (void)loadInfoBoxInitialUserSetup
{
[self performSelectorOnMainThread:#selector(userInitialSetupMainThread) withObject:nil waitUntilDone:NO];
}
- (void)userInitialSetupMainThread
{
// fetch JSON data
NSDictionary *responseJSON = [NSDictionary dictionaryWithDictionary:[self getUserstuff]];
self.myInfoBox.i_statusLabel.text = #"Processing Recieved information";
// breakpoint - nothing changes in the view on the simulator
[myInfoBox.view setNeedsLayout];
// breakpoint - nothing changes in the view on the simulator
[myInfoBox.view setNeedsDisplay];
// breakpoint - nothing changes in the view on the simulator
[myInfoBox.parentViewController.view setNeedsLayout];
// breakpoint - nothing changes in the view on the simulator
[myInfoBox.parentViewController.view setNeedsDisplay];
// breakpoint - nothing changes in the view on the simulator
[myInfoBox performSelectorOnMainThread:#selector(updateValuesForTitle:) withObject:#"test" waitUntilDone:YES];
// breakpoint - nothing changes in the view on the simulator
[self.view setNeedsLayout];
// breakpoint - nothing changes in the view on the simulator
[self.view setNeedsDisplay];
// breakpoint - nothing changes in the view on the simulator
self.myInfoBox.i_statusLabel.text = #"Reloading...";
// breakpoint - nothing changes in the view on the simulator
[self readStuffFromDB];
sleep(2);
//disabled view removal for testing..
//[self.myInfoBox.view removeFromSuperview];
// breakpoint - nothing changes in the view on the simulator
}
What happens for me in the testing is that the myInfoBox object is created on screen when the -(void)loadMainView method is complete, then I can see on screen the "myInfoBox" in the background while the alertView in front (for testing...) at this point the screen is responsive and I can select the YES, once I select yes the delegate method is called.
As I commented in the source file, using breakpoints I am monitoring the simulator and following the code, never the less the changed label values are not reflected while I am still in the - (void)userInitialSetupMainThread method, but once it finishes the view updates with the latest set .text value!! grrr..
Also, the source for the myInfoBox class:
#interface InfoBoxController : UIViewController {
IBOutlet UILabel* i_titleLabel;
IBOutlet UILabel* i_statusLabel;
IBOutlet UIImageView* i_loadingImage;
IBOutlet UIImageView* i_background;
IBOutlet UIActivityIndicatorView* i_activityIndicator;
}
#property(nonatomic, retain) IBOutlet UILabel* i_titleLabel;
#property(nonatomic, retain) IBOutlet UILabel* i_statusLabel;
#property(nonatomic, retain) IBOutlet UIImageView* i_loadingImage;
#property(nonatomic, retain) IBOutlet UIImageView* i_background;
#property(nonatomic, retain) IBOutlet UIActivityIndicatorView* i_activityIndicator;
//- (void)updateValuesForTitle:(NSString *)title Label:(NSString *)label;
- (void)updateValuesForTitle:(NSString *)title;
#end
#implementation InfoBoxController
#synthesize i_titleLabel, i_statusLabel, i_loadingImage, i_background;
#synthesize i_activityIndicator;
//-(void)updateValuesForTitle:(NSString *)title Label:(NSString *)label
-(void)updateValuesForTitle:(NSString *)title
{
self.i_titleLabel.text = title;
self.i_statusLabel.text = title;
[self.i_titleLabel setNeedsDisplay];
[self.i_statusLabel setNeedsDisplay];
}
Sorry for the LOONG post :)
PLEASE ASSIST!
At the risk of sounding unhelpful, that's kind of just how it works. If you have long-running code in the main event loop (i.e., you don't explicitly create a thread or similar), the operating system won't be able to update the UI.
To update the UI while your code is running, you either need to run your complex operation in the back ground using thread, NSOperationQueue, etc, or just break it into smaller steps and return control to the main loop occasionally so that the UI can be updated.