Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 swift:tableView中的图像_Ios_Swift - Fatal编程技术网

Ios swift:tableView中的图像

Ios swift:tableView中的图像,ios,swift,Ios,Swift,有TableViewController和ViewController。我想在单元格TableViewController中显示图像,前提是ViewController中的跟踪时间大于1 我使用此代码来执行此操作: override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueR

TableViewController
ViewController
。我想在单元格
TableViewController
中显示图像,前提是
ViewController
中的跟踪时间大于1

我使用此代码来执行此操作:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: String(format: "Cell%d", indexPath.row), for: indexPath)

    var timeString = 0
    if indexPath.row >= 0 {
        timeString = UserDefaults.standard.integer(forKey: "currentTime\(indexPath.row)")
    }
    let timeInSeconds = timeString    

    if timeInSeconds > 1 {

        //show image

    }
}
此代码允许在单击的单元格中显示图像。移动到
ViewController
并返回后,用户将在单元格中看到图像

但有时由于
视图控制器中的操作(如果曲目编号更改),我需要在多个单元格中显示多个图像


怎么做?

请按以下步骤做,我相信它会对你有用

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: String(format: "Cell%d", indexPath.row), for: indexPath)

    var timeString = 0
    if indexPath.row >= 0 {
        timeString = UserDefaults.standard.integer(forKey: "currentTime\(indexPath.row)")
    }
    let timeInSeconds = timeString    

    if timeInSeconds > 1 {
        //show image
    }else{
       // Set your UIImageView to nil here...
       // imageView.image = nil
    }
}

声明一个bool变量。在听了track0、track1、track2之后,将该bool变量设为true,并在cellForRowAt()show image中检查bool是否为true。

我无法理解您的问题。你能简单描述一下吗?我完全知道你想做什么。但我不能回答你的问题。@girish_pro如果我在
ViewController
中听track0、track1、track2,我想在
TableViewController
中用cell0、cell1、cell2显示图像。你们听懂了吗?@kaizippo若我在ViewController中听track0,track1,track2,我想在TableViewController的cell0,cell1,cell2中显示图像。怎么做?这是我的问题。不要从
cellForRow
中的
UserDefaults
加载数据。此方法经常被调用。在
viewdiload
中获取整数值并将其放入模型中。如果我在
ViewController
中收听track0、track1、track2,我想在
TableViewController
中的cell0、cell1、cell2中显示图像。怎么做?如果用户收听track0,track1,track2,track3?在viewDidLoad中使bool变量为false。因此,在cellForRowAt方法中,检查bool==true->show images else是否显示您想要的任何内容。如果有70首曲目呢?如果收听曲目并在完成收听后,您想做什么?如果用户收听曲目,我想在表格单元格中显示图像。例如:现在用户在
ViewController
中收听track0、track1、track2。这意味着在
TableViewController
中,用户将在cell0、cell1和cell2中看到3幅图像。明天用户收听用户收听
ViewController
中的track3、track4、track5。这意味着在
TableViewController
中,用户将在cell3、cell4、cell5中看到6个图像+cell0、cell1、cell2中的图像(昨天保存)。