用于RESTful UIButton操作的UX

时间:2015-11-02 06:32:18

标签: ios rest uibutton user-experience

UIButton重新触发其动作(即通过GET,POST或PUT请求)。是否应该以开头禁用按钮的方式封装动作,而结束再次启用它?

- (IBAction)buttonTapped:(id)sender {

    self.button.enabled = NO;

    ... RESTful API . . . 

    self.button.enabled = YES;


}

iOS中按钮操作的最佳用户体验是什么?

2 个答案:

答案 0 :(得分:1)

按钮点击将在主线程上执行,因此实现同步调用会给你带来很多问题。根据您的网络客户端API,实现委托方法(您的类应符合协议)或回调。

- (IBAction)buttonTapped:(id)sender {
    self.button.enabled = NO;
    ...
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
...
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    ...
    self.button.enabled = YES;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    ...
    self.button.enabled = YES;
}

实施例

  1. NSURLConnection http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example
  2. AFNetworking http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial

答案 1 :(得分:1)

我想说,你需要阻止两次或更多次调用REST API函数,并且禁用按钮的方法是可行/赞赏的。 不要忘记使用某种活动指标来遵循Apple规则。

编辑:这实际上取决于你的实现,我在这种情况下使用AFNetworking库处理REST API调用,然后使用异步调用构建函数,当调用正常或失败时只需将按钮释放为再次激活。