如何在注册的水龙头数量后删除或停止表视图中的按钮

时间:2012-11-09 19:01:10

标签: objective-c ios uitableview

我在表视图中有一个添加行的按钮。在最多五行之后,我想停止用户添加。目前,我在按钮重复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.
    }



  }
}

1 个答案:

答案 0 :(得分:2)

如果您有AlertView,可以输入此代码以禁用按钮:

[(UIButton *)sender setEnabled:NO];

或隐藏按钮:

 [(UIButton *)sender setHidden:YES];