我有1 UITableView
在每一行都有多个UIButton(命名为“打开”按钮,带有不同的标签),我为它们设置了标签。现在,点击每行中的任何按钮后,它会显示UIView
( detailView )。在detailView上有1个“提交”按钮。我想当用户点击“提交”按钮时,选中标签的“打开”按钮被禁用。我怎样才能做到这一点?我用了这段代码:
使用多个“打开”按钮创建表视图的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
[market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];
[market setTag:3000];
[market setFrame:CGRectMake(200, 6, 30, 30)];
[cell.contentView addSubview:market];
}
marketButton = (UIButton *)[cell.contentView viewWithTag:3000];
[marketButton setTag:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
return cell;
}
点击“打开”按钮时的代码:
- (void)marketPressedAction:(id)sender
{
UIButton *button = (UIButton *)sender;
buttontag = button.tag;
NSLog(@"Market button click at row %d",buttontag);
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateHighlighted];
[sender setSelected:NO];
}
else {
[sender setImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateSelected];
[sender setSelected:YES];
}
}
}
答案 0 :(得分:0)
UIButton *btn = (UIButton *)sender;
btn.enabled = NO;
在按钮点击方法
中尝试这个答案 1 :(得分:0)
如果您希望在单击“提交”按钮后禁用“打开”按钮,则应使用代理
答案 2 :(得分:0)
已编辑:
将marketPressedAction
参数id
更改为UIButton *
并编写以下代码
-(void)marketPressedAction:(UIButton *)sender
{
[sender setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateHighlighted];
[sender setImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateSelected];
/// Here set you image ////////////////
[sender setImage:[UIImage imageNamed:@"myCustome.png"] forState:UIControlStateNormal];
[self createMarketPlaceForm]; // call detailView
sender.enabled = NO;
sender.userInteractionEnabled = NO;
}