每个UITableViewCell都有一个按钮。我想执行刷新RowatIndex。只要单击按钮。执行AFNetworking的POST请求方法。我的ViewdidLoad方法中有GET Request Method。
如果在UITableViewCell中单击按钮并且加载动画为完成时如何更新数据是Basecamp应用程序?
答案 0 :(得分:0)
尝试以下方法:
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];
}