Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否修改静态UITableView单元格中的文本?_Ios_Cocoa Touch_Uitableview_Uistoryboard - Fatal编程技术网

Ios 是否修改静态UITableView单元格中的文本?

Ios 是否修改静态UITableView单元格中的文本?,ios,cocoa-touch,uitableview,uistoryboard,Ios,Cocoa Touch,Uitableview,Uistoryboard,我正在使用在故事板文件中创建的“静态单元格”表视图。但是,我想在更改设置时更新其中一个单元格上的文本 我正在推一个视图控制器,它会更新设置。我试图在单元格从堆栈中弹出时使用回调来更改单元格的文本,但此时单元格显然已被回收或重用,因此旧对象已脱离屏幕,不再在表视图中使用 是否有方法可以更新此文本并使其永久化(这样当单元格从屏幕上滚下并返回时,新值仍会出现)?假设您的表视图层次结构符合以下要求: Table View (static cells) - Table View Section -

我正在使用在故事板文件中创建的“静态单元格”表视图。但是,我想在更改设置时更新其中一个单元格上的文本

我正在推一个视图控制器,它会更新设置。我试图在单元格从堆栈中弹出时使用回调来更改单元格的文本,但此时单元格显然已被回收或重用,因此旧对象已脱离屏幕,不再在表视图中使用


是否有方法可以更新此文本并使其永久化(这样当单元格从屏幕上滚下并返回时,新值仍会出现)?

假设您的表视图层次结构符合以下要求:

Table View (static cells)
 - Table View Section
  - Table View Cell
    - UILabel (with the text property you want to modify)
  • 在代码中声明一个IBOutlet
    UILabel
    ,并将其连接到上面表视图层次结构中故事板的
    UILabel
  • 在回调方法中,根据需要设置
    UILabel
    的文本属性

  • 您可以将要更改的文本存储为属性,并在以下位置使用:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
    
        switch (indexPath.section, indexPath.row) {
        case (0, 3):
            cell.textLabel?.text = yourProperty
    
        default: break
        }
    
        return cell
    }
    

    为什么要更新屏幕外单元格的文本?你应该意识到电池是可以回收的。相应地更新它们。您必须不使用静态单元格。您必须设置一个委托,以便在单元格再次出现时生成该单元格的更改版本。