UIactivityindicator 在我的项目中不起作用

发布于 2024-08-16 02:49:27 字数 1330 浏览 6 评论 0原文

我正在尝试在我的 iPhone 应用程序中处理 ActivityIndi​​cator。

但这根本不起作用。

在我的项目中,我有一个 UISearchbar。

当人们输入关键字并单击搜索结果时,将在 UIWEbview 中显示字符串。

我真的希望活动指示器在等待数据时显示并显示动画,并在加载数据时停止。

这是我使用的一些代码:

@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 =@"<span style='color:#3B5998; font-size:25px;font-weight: bold;'>I love you too </span> <span style='color:#666; font-size:18px;'> -rte,-rt </span> ;

[myWebview loadHTMLString:rs baseURL:nil]; 
}

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


@end

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 =@"<span style='color:#3B5998; font-size:25px;font-weight: bold;'>I love you too </span> <span style='color:#666; font-size:18px;'> -rte,-rt </span> ;

[myWebview loadHTMLString:rs baseURL:nil]; 
}

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


@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笛声青案梦长安 2024-08-23 02:49:27

在你的例子中,你正在“加载”一个字符串,这将是瞬时的,所以(因为iPhone结合了动画)指示器永远不会有动画。

您应该使用远程 URL 来尝试您的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文