我一直在努力从UITableViewController中的UITableViewCell访问标签..
类reboundShotsCount的代码如下所示:
此类在ShotDetail类中定义,它是UITableViewController的子类。
public class reboundShotsCount : UITableViewCell {
@IBOutlet public var reboundCountLabel: UILabel!
}
ShotDetail中的代码
var shots : [Shot] = [Shot]()
var shot : Shot!
var comments : [Comment] = [Comment]()
var previousImageManager : ImageManager!
override func viewDidLoad() {
super.viewDidLoad()
// Enable GIF decompression
self.previousImageManager = ImageManager.shared
let decoder = ImageDecoderComposition(decoders: [AnimatedImageDecoder(), ImageDecoder()])
let loader = ImageLoader(configuration: ImageLoaderConfiguration(dataLoader: ImageDataLoader(), decoder: decoder), delegate: AnimatedImageLoaderDelegate())
let cache = AnimatedImageMemoryCache()
ImageManager.shared = ImageManager(configuration: ImageManagerConfiguration(loader: loader, cache: cache))
title = shot.title
let reboundShotCell = reboundShotsCount()
// the countLabel returns nil
let countLabel = reboundShotCell.reboundCountLabel
// The error comes here.
countLabel.text = "\(shot.reboundCount)"
let api = DribbleObjectHandler()
api.loadComments(shot.commentsUrl, completion: didLoadComments)
api.loadShots(shot.reboundUrl, completion: didLoadReboundShots)
}
我知道代码在viewDidLoad中创建了一个新的reboundShotsCount实例。 如果我在reboundShotsCount类中定义shot变量。它返回没有。
我被困住了,不知道该怎么办?
答案 0 :(得分:0)
您需要在cellForRowAtIndexPath
的{{1}} dataSource方法中设置文字....您所做的是在tableview
中,此时viewDidLoad
尚未加载tableview
-