UIactivityindicator 在我的项目中不起作用
我正在尝试在我的 iPhone 应用程序中处理 ActivityIndicator。
但这根本不起作用。
在我的项目中,我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的例子中,你正在“加载”一个字符串,这将是瞬时的,所以(因为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.