我想iPhone:隐藏在UITableViewCell中的附件按钮的基础上正确故事板
什么有一个tableview.I只是想通过点击它在TableViewCell躲UIButtonTypeContactAdd附件。
我的问题
当我拍了拍附件按钮A(我只在整个过程中抽头),它正确墙根。但是当我向下滚动桌面时,我发现另一个附件按钮B可笑地隐藏起来。滚动快速到tableview中的顶侧之后,按钮B家伙在那里再次,同时另一个按钮C墙根...
很可惜我不能把图像在我post.Hope你能理解发生了。
代码
的tableView:的cellForRowAtIndexPath:static NSString *CellIdentifier = @"All Name Showing Table"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } if(!cell.accessoryView){ UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; cell.accessoryView = button; }
- (IBAction)buttonTapped:(UIButton *)sender
{
UITableViewCell *tvc = (UITableViewCell *)[sender superview];
NSString *peopleTapped = [NSString stringWithFormat:@"you have favored %@",tvc.textLabel.text];
NSLog(@"%@",peopleTapped);
sender.hidden = YES;
}
是所有这一切都因为电池再利用的机制呢?
对不起,我英文很差。
谢谢!
它确实有效!非常感谢。我创建了一个NSMutableDictionary来为键保存一系列buttonModelArray,所以我可以使用indexPath.section和indexPath.row替换代码中的“标记”。这是一种有效的方法吗?这是我第一次在stackoverflow上获得帮助。^^ – studyro 2012-02-29 06:07:33