0

我在表格视图中有一个添加行的按钮。最多五行后,我想停止用户添加。目前,我在按钮收到 5 次点击后显示警报。

如何阻止用户在此之后使用按钮?设置为隐藏不会作为它的自定义子类工作,并且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.
    }



  }
}
4

1 回答 1

2

在您拥有 AlertView 的地方,您可以键入以下代码来禁用按钮:

[(UIButton *)sender setEnabled:NO];

或隐藏按钮:

 [(UIButton *)sender setHidden:YES];
于 2012-11-09T19:13:57.473 回答