【发布时间】:2017-07-02 01:15:59
【问题描述】:
我正在使用一个标签栏控制器,我正在尝试从我的其他标签栏视图控制器访问默认设置。我在不同的函数中尝试了这个,如下所示,它运行良好,但由于某种原因它在这里不起作用。每当调用它时,它都会提出错误:FirstViewController().defaults。有人知道为什么会这样吗?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = TableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
TableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
var photo: Photo
let description = FirstViewController().description
if(searchController.isActive){
photo = self.filteredPhotos[indexPath.row]
} else {
photo = self.photosArray[indexPath.row]
}
cell.textLabel!.text = photo.name
if(FirstViewController().defaults.data(forKey: photo.name + "image") as UIImage != nil){
cell.imageView?.image = FirstViewController().defaults.data(forKey: photo.name + "image") as UIImage
}
print(photo.name)
print("TableView2Finished")
return cell
}
【问题讨论】:
-
欢迎来到 Stack Overflow!您能否详细说明您的代码如何“不起作用”?你期待什么,实际发生了什么?如果您遇到异常/错误,请发布它发生的行和异常/错误详细信息。请edit这些详细信息,否则我们可能无法提供帮助。
-
您正在尝试访问 FirstViewController 类的默认值,而不是 FirstViewController 实例上的默认值。这是故意的吗?你真的知道有什么不同吗?
标签: ios iphone swift uitableview uiviewcontroller