我在 TableView 中有一个添加行的按钮。在最多五行之后,我想停止用户添加。目前,我会在按钮收到 5 次点击后显示警报。
我怎样才能阻止用户在这之后使用按钮?设置为 hidden 将无法工作,因为它是一个自定义子类,并且 property hidden
在类中找不到
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.shadowColor = [UIColor darkGrayColor];
titleLabel.text = self.distributionBoard.dbRef;
titleLabel.font = [UIFont boldSystemFontOfSize:15.0f];
[titleLabel sizeToFit];
self.navigationItem.titleView = titleLabel;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
// Add new appliance button to the table view's footer view
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 0, 300.0f, 100.0f)];
footerView.backgroundColor = [UIColor clearColor];
UIButton *newBoardButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
CGRect buttonFrame = newBoardButton.frame;
buttonFrame.origin.x = footerView.frame.size.width - buttonFrame.size.width;
newBoardButton.frame = buttonFrame;
[newBoardButton addTarget:self action:@selector(addCircuitButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:newBoardButton];
self.tableView.tableFooterView = footerView;
}
.....
////limit to five appliances
- (void)addCircuitButtonPressed:(id)sender {
LogCmd();
Circuit *circuit = [[ICCircuitManager manager] newCircuit];
circuit.distributionBoard = self.distributionBoard;
circuit.circuitReference = [NSString stringWithFormat:@"%d", [self.circuits count] + 1];
circuit.createdAt = [NSDate date];
circuit.modifiedAt = [NSDate date];
[self.distributionBoard addCircuitsObject:circuit];
[self loadData];
[self.tableView reloadData];
{
m_buttonTouchCount++;
if ( m_buttonTouchCount == 4)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iCertifi"
message:@"Maximum number of appliances reached"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
// m_buttonTouchCount = 0; // reset to 0 here if required.
}
}
}
最佳答案
在您有 AlertView 的地方,您可以键入此代码来禁用按钮:
[(UIButton *)sender setEnabled:NO];
或隐藏按钮:
[(UIButton *)sender setHidden:YES];
关于objective-c - 如何在注册点击量后删除或停止 TableView 中的按钮工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13314270/