所以我在我的 Uitableview 的每个表格单元格中嵌入了两个按钮。我允许用户编辑按钮标题。但是,一旦用户将单元格滚动出屏幕,标题就会再次变为空白。知道如何解决这个问题吗?这是我的代码:
表视图方法:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
addWeightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addRepButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[addWeightButton addTarget:self action:@selector(weightPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[addRepButton addTarget:self action:@selector(repPressedAction:) forControlEvents:UIControlEventTouchUpInside];
addWeightButton.frame = CGRectMake(110.0f, 5.0f, 75.0f, 30.0f);
addRepButton.frame = CGRectMake(260.0f, 5.0f, 50.0f, 30.0f);
[addWeightButton setTag:indexPath.row];
[addRepButton setTag:indexPath.row];
[cell addSubview:addWeightButton];
[cell addSubview:addRepButton];
return cell;
}
编辑按钮标题方法
-(void) editWeightNumber:(int)value {
[[routine objectAtIndex:index] addWeight:value atIndex:selectedWeightBox];
NSString* weights = [NSString stringWithFormat:@"%i", [[routine objectAtIndex:index] getWeight:selectedWeightBox]];
[weightSender setTitle:weights forState:UIControlStateNormal];
}