objective-c - 如何在注册点击量后删除或停止 TableView 中的按钮工作

标签 objective-c ios uitableview

我在 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/

相关文章:

ios - 使用 dispatch_async 在 willDisplayCell 中很有用

ios - Apache BrowserMatch iOS 禁用 keepalive。匹配所有 iOS 版本?

ios 8 Swift - 带有嵌入式 CollectionView 的 TableView

ios - Swift 中的 PFQueryTableViewController 使用 Cloud Code 函数

ios - 通过两个 ViewController 传输数据

objective-c - insertNewObjectForEntityForName 返回 nil

ios - 无法通过 UIView 通过 swift 创建 pdf?

ios - 我添加了 ScatterPlot View 但我无法在页面上看到它

objective-c - iOS 8 和 XCode 6 上的 AVFoundation 语音合成

ios - 在 iPad 上锁定 UIViewController 方向