iOS 開發指南 第15章 訪問Web Service之反饋網路資訊改善使用者體驗

來源:互聯網
上載者:User

標籤:

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之反饋網路資訊改善使用者體驗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.