标签:
1 使用下拉刷新控件改善用户体验
表视图UIRefreshControl类型的refreshControl属性,不需要考虑控件布局问题
初始化:
设置attributedTitle属性 添加事件处理机制
- (void)viewDidLoad {
[super viewDidLoad];
//查询请求数据
action = QUERY;
[self startRequest];
//初始化UIRefreshControl
UIRefreshControl *rc = [[UIRefreshControl alloc] init];
rc.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
[rc addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];
self.refreshControl = rc;
}
事件处理方法:
-(void) refreshTableView
{
if (self.refreshControl.refreshing) {
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];
//查询请求数据
action = QUERY;
[self startRequest];
}
}
请求成功之后需要停止刷新
//重新加载表视图
-(void)reloadView:(NSDictionary*)res
{
if (self.refreshControl) {
[self.refreshControl endRefreshing];
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
}
NSNumber *resultCodeObj = [res objectForKey:@"ResultCode"];
if ([resultCodeObj integerValue] >=0)
{
self.objects = [res objectForKey:@"Record"];
[self.tableView reloadData];
} else {
NSString *errorStr = [resultCodeObj errorMessage];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"错误信息"
message:errorStr
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];
}
}
2 使用活动指示器控件
UIActivityIndicatorView 可放置在工具栏 导航栏以及弹出的对话框中
方法和属性:startAnimating开始动画 stopAnimating停止动画 isAnimating判断是否在旋转 hidesWhenStopped属性用于设置控件停止时是否隐藏
- (void)viewDidLoad {
------
//查询请求数据
action = QUERY;
[self startRequest];
[self showActivityIndicatorViewInNavigationItem];
}
//在导航栏中显示等待对话框
-(void) showActivityIndicatorViewInNavigationItem
{
UIActivityIndicatorView *aiview = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
self.navigationItem.titleView = aiview;
[aiview startAnimating];
self.navigationItem.prompt = @"数据加载中...";
}
3 网络活动指示器
由于使用MKNetworkKit框架时内置了网络活动指示器功能,所以只要有网络请求,都会出现网络指示器。
若使用NSURLRequest,就需要自己添加代码:
[UIApplication shareApplication].networkActivityIndicatorVisble=YES/ON;
iOS 开发指南 第15章 访问Web Service之反馈网络信息改善用户体验
标签:
原文地址:http://www.cnblogs.com/haugezi/p/4823620.html