Hi guys, I have a MainView with a lot of subviews! In one of that subview there is a WebView that check if there is a connection. The problem is that check connection ALWAYS at the startup of my app.. I want load this subview only when is opened...is that possible??
this is my code:
MainView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class VistaUno;
@class VistaDue;
@class Vistatre;
@class risposta;
@class VistaQuattro;
@interface MainView : UIView {
IBOutlet VistaUno *vistaUno;
IBOutlet VistaDue *vistaDue;
IBOutlet Vistatre *vistaTre;
IBOutlet risposta *Risposta; //this is the view that I want to load separately
IBOutlet VistaQuattro *vistaQuattro;
}
Risposta.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class MainView;
@interface risposta : UIView <UIWebViewDelegate>{
IBOutlet MainView *mainView;
}
The Webview is loaded trouhg a UIViewController....
WebViewControllerRisposta.h
#import <UIKit/UIKit.h>
@interface WebViewControllerRisposta : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *webview2;
IBOutlet UIActivityIndicatorView *m_activity;
}
@property (nonatomic, retain) UIActivityIndicatorView *m_activity;
@property (nonatomic, retain) UIWebView *webview2;
@end
WebViewControllerRisposta.m
#import "WebViewControllerRisposta.h"
@implementation WebViewControllerRisposta
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.google.it";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webview2 loadRequest:requestObj];
}
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webview2 {
m_activity.hidden= FALSE;
[m_activity startAnimating];
NSLog(@"Web View Did started loading...");
}
- (void)webViewDidFinishLoad:(UIWebView *)webview2 {
m_activity.hidden= TRUE;
[m_activity stopAnimating];
NSLog(@"Web View finish loading");
//Ricordarsi di aggiungere il codice per eliminare l'acquisto
}
- (void)webView:(UIWebView *)webview2 didFailLoadWithError:(NSError *)error {
[m_activity stopAnimating];
m_activity.hidden= TRUE;
NSLog(@"Error %i", error.code);
if (error.code == NSURLErrorCancelled) return; // this is Error -999
// error handling for "real" errors here
if (error != NULL) {
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"NETWORK ERROR"
message:@"Sembra che al momento non vi è una connessione dati attiva! Per scaricare i nuovi Enigmi o inviare la tua risposta è necessaria una connessione Internet!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// 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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[webview2 dealloc];
[super dealloc];
}
@end