views:

215

answers:

1

Hello, I´m trying to deal with activityIndicator in my iPhone app..But it doesn´t work at all. Inside my project I have a UISearchbar. When people put the keyword and click the search result will show string in UIWEbview. I really want the activity indicator show and animate while waiting for data and Stop when data is loaded. Here is some of the code I use :

@implementation myFirstappController @synthesize myWebview, activityIndicator;

  • (void)webViewDidStartLoad:(UIWebView *)myWebview {

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [activityIndicator startAnimating]; }

  • (void)webViewDidFinishLoad:(UIWebView *)myWebview {

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [activityIndicator stopAnimating]; }

///Here is code inside the UISearchbar

  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

NSString *keywords = searchBar.text; NSString *infos = [NSString stringWithFormat: @"%@", keywords]; NSString *rs=nil;

if ([infos isEqualToString:@"Iloveyou"]){ rs =@"I love you too -rte,-rt ;

[myWebview loadHTMLString:rs baseURL:nil]; }

  • (void)dealloc { [myWebview release]; //<-------JUST FILL THIS LINE********************** [activityIndicator release]; [searchBar release]; [super dealloc]; }

@end

A: 

In your example you're "loading" a string, which will be instantaneous, so (because the iPhone combines animations) the indicator will never animate.

You should try your code with a remote URL.

Oliver White
Hmm, but my point is I will not work with the web, The reason that i choose UIWebview to display data is because it´s easy to adit the text with colour, style etc. Do you think here are some way I will solv this ?thank you for some further help and answer.
iGutt
My point was that if you see the animation when loading a remote URL then you'll know it doesn't normally animate because the time between starting and stopping the animation is too quick.You can force the system to flush animations, but this is part of a private API and now that Apple is running binaries through static analysis, I would NOT recommend using it.If you are "loading" static HTML, the load time will always be too quick to display the animations, so I wouldn't bother.
Oliver White
Could you please give me the advice ?If I will make app like this to deal with string (which have ability ti play with rich-rext such ad colour/ style, etc.)I have used Label but i´s so boring when it can not play maything with :(Plase give me some advice. If you will please.Yhank you so much .
iGutt
I would only use UIWebView if you have HTML content to display, e.g. an RSS reader. UIWebView uses a lot of memory and is slow for your purposes. You don't need UIWebView to add colors/styles to the text.
Oliver White
What is best? if you were me...I´M NEW WITH THIS.Thank for help :)hope o hear from u.
iGutt
There is no best. What options have you tried?
Oliver White