Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
My view controller directs the file "feature.htm" to be loaded upon clicking. When it loads, a full-page GIF animation plays, then stops. This is correct behavior.

If you press the Back button in the Navigation Bar, then go back to "feature.htm" again, the GIF animation does not replay. It stays in its end position. It only replays if one restarts the app.

How do I get it to replay for each click to the page without restarting the app?

Thanks,
Steve
 
I did a brief search, and it doesn't look like there's anyway you can control an animated gif as a standard img element using JavaScript.

You could also try using the loadRequest: method with NSURLRequestReloadIgnoringLocalCacheData to force it to reload without using the cache.

Depending on what else is in your web page, you might be able to replace it entirely with standard UIViews.
 
What exactly happens in your code when you press the Back button? Are you allowing the view controller with the web view in it to be released? Are you creating a new view controller and web view when the view controller is shown again? UIWebView has a reload method. What happens if you call that in say viewDidLoad or viewWillAppear? Are you using the goBack and goForward methods?
 
I use the navigation controller Apple provides in the AppDelegate.m:

Code:
	// add the navigation controller's view to the window
	[window addSubview: navigationController.view];
	[window makeKeyAndVisible];



There's very little code on the Feature1ViewController.m page for the Feature1.htm page, which has just the animated GIF, nothing else:

Code:
- (void)viewDidLoad
{
	[super viewDidLoad];
	
	self.title = @"Features";
	
	CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
	applicationFrame.origin.y = 0;
	UIWebView *webView = [[UIWebView alloc] initWithFrame:applicationFrame];
	webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
	
	NSString *basePath = [[NSBundle mainBundle] bundlePath];
	NSURL *baseURL = [NSURL fileURLWithPath:basePath];
	NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Feature1" ofType:@"htm"];
	NSString *htmlString = [NSString stringWithContentsOfFile:filePath];
	if (htmlString) {
		[webView loadHTMLString:htmlString baseURL:baseURL];
	}
	
	[self.view addSubview:webView];
	[webView release];
}


The MainViewController.m that calls the above page references the above here:


Code:
- (void)viewDidLoad
{	
	[super viewDidLoad];
	
	
	self.title = @"Features"; // This adds the title to the table's page at top.
	
	// construct the array of page descriptions we will use (each description is a dictionary)
	//
	self.menuList2 = [NSMutableArray array];
	
	
	Feature1ViewController *feature1ViewController = [[Feature1ViewController alloc]
													initWithNibName:@"Feature1ViewController" bundle:nil];
	[self.menuList2 addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
							   @"Wheels", kTitleKey,
							   feature1ViewController, kViewControllerKey,
							   nil]];
	[feature1ViewController release];


I'll look up the reload method and see what it will do.

Thanks!
Steve
 
I added the reload where shown at bottom, but it has no effect on the code:

Code:
- (void)viewDidLoad
{
	[super viewDidLoad];
	
	self.title = @"Features";
	
	CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
	applicationFrame.origin.y = 0;
	myWebView = [[UIWebView alloc] initWithFrame:applicationFrame];
	myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
	
	NSString *basePath = [[NSBundle mainBundle] bundlePath];
	NSURL *baseURL = [NSURL fileURLWithPath:basePath];
	NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Feature1" ofType:@"htm"];
	NSString *htmlString = [NSString stringWithContentsOfFile:filePath];
	if (htmlString) {
		[myWebView loadHTMLString:htmlString baseURL:baseURL];
	}
	
	[self.view addSubview:myWebView];
	[myWebView release];
	
}


- (void)viewWillAppear:(BOOL)animated
{
	//  Put reload code here so animated GIF will play each time its page appears. DOES NOT WORK. 
	[myWebView reload];
	
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.