0

テーブル ビューに行を追加するボタンがあります。最大 5 行の後、ユーザーの追加を停止したいと考えています。現在、ボタンが 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 に答える