很抱歉,如果这很简单。基本上,这是我的代码:
MainViewController.h :
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <UIWebViewDelegate, FlipsideViewControllerDelegate> {
IBOutlet UIWebView *webView;
IBOutlet UIActivityIndicatorView *spinner;
}
- (IBAction)showInfo;
@property(nonatomic,retain) UIWebView *webView;
@property(nonatomic,retain) UIActivityIndicatorView *spinner;
@end
MainViewController.m :
#import "MainViewController.h"
#import "MainView.h"
@implementation MainViewController
@synthesize webView;
@synthesize spinner;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
NSURL *siteURL;
NSString *siteURLString;
siteURLString=[[NSString alloc] initWithString:@"http://www.site.com"];
siteURL=[[NSURL alloc] initWithString:siteURLString];
[webView loadRequest:[NSURLRequest requestWithURL:siteURL]];
[siteURL release];
[siteURLString release];
[super viewDidLoad];
}
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[spinner stopAnimating];
spinner.hidden=FALSE;
NSLog(@"viewDidFinishLoad went through nicely");
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[spinner startAnimating];
spinner.hidden=FALSE;
NSLog(@"viewDidStartLoad seems to be working");
}
- (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void)dealloc {
[spinner release];
[webView release];
[super dealloc];
}
@end
不幸的是,没有任何内容写入我的日志,由于某些原因UIActivityIndicator
似乎永远不会出现。这里出了什么问题?
谢谢大家
杰克
答案 0 :(得分:4)
您需要设置UIWebView委托。您实现了协议,但您从未告诉UIWebView此类是委托,因此永远不会调用这些方法。
webView.delegate = self;
另外,您可能想查看有关如何实现UIWebViewDelegate方法的question/answer。
答案 1 :(得分:1)
- webViewDidFinishLoad:
在成功加载相关网址的内容后发送给Web View的委托。您是否通过在Safari中检查URL确认该URL有效?您是否仔细检查了代理连接?