ios - 向 UITableView 发送自定义 TableViewCell 操作

标签 ios objective-c uitableview tableviewcell

在一个小的 iOS 应用程序上工作,我为我的 UITableView 制作了一个自定义的 tableview 单元格(和它自己的类)。单元格上的两个东西是“添加”和“删除”按钮。单击这些时,我需要更新 UITableView 中的数组对象,但由于表格单元格是一个单独的类,我如何将这些更改发送到 UITableView 类?

例如,下面的代码用于单元格上的“删除”按钮:

- (IBAction)decrementItem:(id)sender {
    int count = (int)[self.specificItemCount.text integerValue];
    //Cannot have negative amount of food
    if(count == 0) {
        return;
    } else {
        count--;
        self.specificItemCount.text = [NSString stringWithFormat:@"%i",count];
    }

但是当单击该按钮时,我需要在表格 View 中更新我的数组对象,我该怎么做?

最佳答案

在你的单元类上定义一个你的 tableview 类将实现的协议(protocol)。这是一个例子:http://www.tutorialspoint.com/ios/ios_delegates.htm .然后将您的表格 View 设置为单元格上的委托(delegate)(确保使用弱引用)。

关于ios - 向 UITableView 发送自定义 TableViewCell 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30875682/

相关文章:

ios - 将 iOS 崩溃报告导入 Xcode 6.1 时出现问题

objective-c - OS X 中的 WKWebView cacheDisplayInRect 屏幕截图

ios - 新屏幕上的 UITextField 将不接受输入

ios - `Unable to dequeue a cell with identifier MyCell`

ios - UITableView beginUpdates/endUpdates 滚动时使滚动跳转

ios - X.509 RSA 加密/解密 iOS

ios - 贴纸包界面生成器 Storyboard编译器错误组

ios - 如何从亚马逊 SNS 主题取消订阅 iOS 设备?

iPhone:自动释放对象内存泄漏?

ios - 在 TableView 中从底部添加新数据