希望我正确认识你的问题:你想点击一个单元格,并有一个活动的指标开始动画?
我个人并不具有对所有的人的活动的指标,然后隐藏和暴露打扰他们,这使得它有点痛的启动和停止的正确指标。
我如何在其他应用程序做它是一个指标在didSelectRow阶段添加到细胞,我们可以知道我们点击了哪个小区,并立即添加单元格:
- (void)tableView:(UITableView *)tableView_ didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView_ reloadData];
// This code will create and add an activity indicator
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UITableViewCell * cell = [tableView_ cellForRowAtIndexPath:indexPath];
cell.accessoryView = activityIndicator;
[activityIndicator startAnimating];
[tableView_ deselectRowAtIndexPath:indexPath animated:YES];
}
整洁件事这个代码是因为我们在创建单元格时不添加活动指示器意味着我们可以通过刷新tableView来摆脱指示器。在这种情况下,每当我们点击我们摆脱了以前的指标,并添加一个新的。
希望这有助于有点
编辑:如果你想这来自小区按下一个按钮(感谢弗拉基米尔此answer)
这是一次非常简单,可以使用代码发生以上。
[button addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
这将使我们能够找出当按钮被窃听
- (void)checkButtonTapped:(id)sender {
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
// Now we have the indexPath of the cell clicked so we can use the previous code again
[tableView_ reloadData];
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UITableViewCell * cell = [tableView_ cellForRowAtIndexPath:indexPath];
cell.accessoryView = activityIndicator;
[activityIndicator startAnimating];
}
哪里是这段代码被称为:
创建单元格时添加一个目标的按钮? – Stonz2 2015-02-05 20:04:57
In; ' - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { }' – 2015-02-05 20:22:28