【问题标题】:Reloading TableView when JSON POST is Performed?执行 JSON POST 时重新加载 TableView?
【发布时间】:2014-08-21 11:33:45
【问题描述】:

我在每个 UITableViewCell 中都有一个按钮。我想执行刷新 RowatIndex。每当单击按钮时。执行 AFNetworking 的 POST 请求方法。我的 ViewdidLoad 方法中有 GET 请求方法。

如何在 UITableViewCell 中单击按钮并在 Basecamp Application 中加载动画时更新数据?

【问题讨论】:

  • 你的问题有点含糊,你是不是想在你的数据源更新后只更新按下的单元格按钮?

标签: uitableview afnetworking


【解决方案1】:

尝试以下方法:

    NSMutableArray *cellIsRefreshed = [NSMutableArray alloc]initWithCapacity:yourDataArray];
    for(int i=0; i<[yourDataArray count]; i++)
     {
         cellIsRefreshed[i] = @"0";
     }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
      TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_Identifier forIndexPath:indexPath];
      if (cell == nil) {
         cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CELL_Identifier];
      }
      [cell.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];
      if([cellIsRefreshed[indexPath.row] integerValue] ==1)
      {  
         [cell.button setHidden:YES];
         [cell.doneImage setHidden: NO];
      }
      else
      {  
         [cell.button setHidden:NO];
         [cell.doneImage setHidden: YES];
      }
      return cell;
   }
- (void)buttonAction :(UIButton *)sender
  {
     UIButton *button = (UIButton *)sender;
     CGPoint pointInSuperview = [button.superview convertPoint:button.center toView:self.tableView];
     NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:pointInSuperview];
     AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
     NSDictionary *parameters = @{@"foo": @"bar"};
    [manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSLog(@"JSON: %@", responseObject);
         cellIsRefreshed[indexPath.row] = @"1";
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"Error: %@", error);
     }];
     [tableView reloadData];
  }

【讨论】:

  • 我对 'GET' 'POST' 'REQUEST' 没有问题,我无法显示对 Basecamp 应用程序等按钮选择的确认,并且数据未刷新。
  • 你试过[tableview reloadData]; POST 完成后
猜你喜欢
  • 2021-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多