第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在swift中創(chuàng)建自定義tableview單元格

在swift中創(chuàng)建自定義tableview單元格

拉風(fēng)的咖菲貓 2019-08-27 15:31:07
在swift中創(chuàng)建自定義tableview單元我有一個(gè)帶有幾個(gè)IBOutlets的自定義單元類。我已將該課程添加到故事板中。我連接了所有的插座。我的cellForRowAtIndexPath函數(shù)如下所示:override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {         let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SwipeableCell         cell.mainTextLabel.text = self.venueService.mainCategoriesArray()[indexPath.row]         return cell    }這是我的自定義單元類:class SwipeableCell: UITableViewCell {     @IBOutlet var option1: UIButton     @IBOutlet var option2: UIButton     @IBOutlet var topLayerView : UIView     @IBOutlet var mainTextLabel : UILabel     @IBOutlet var categoryIcon : UIImageView     init(style: UITableViewCellStyle, reuseIdentifier: String!) {         super.init(style: style, reuseIdentifier: reuseIdentifier)     }}當(dāng)我運(yùn)行應(yīng)用程序時(shí),我的所有單元格都是空的。我已經(jīng)注銷self.venueService.mainCategoriesArray(),它包含所有正確的字符串。我也試過(guò)把一個(gè)實(shí)際的字符串等于標(biāo)簽,這會(huì)產(chǎn)生相同的結(jié)果。我錯(cuò)過(guò)了什么?任何幫助表示贊賞。
查看完整描述

3 回答

?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊

這適用于使用.xib工作的自定義單元格

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

    let identifier = "Custom"

    var cell: CustomCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCel  

      if cell == nil {
            tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: identifier)
           cell =tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCell
        }return cell}


查看完整回答
反對(duì) 回復(fù) 2019-08-27
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

我也有同樣的問(wèn)題。

一般來(lái)說(shuō),我做的和你一樣。

class dynamicCell: UITableViewCell {

    @IBOutlet var testLabel : UILabel

    init(style: UITableViewCellStyle, reuseIdentifier: String) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }}

并在uitableviewcell方法中:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell :dynamicCell = tableView.dequeueReusableCellWithIdentifier("cell") as dynamicCell

    cell.testLabel.text = "so sad"

    println(cell.testLabel)

    return cell;}

是的,tableview什么都沒(méi)顯示!但是猜猜看,它實(shí)際上顯示了一些東西......因?yàn)槲覐膒rintln(cell.testLabel)獲得的日志顯示所有標(biāo)簽實(shí)際上都顯示出來(lái)了。

但!他們的框架很奇怪,有這樣的東西:

frame =(0 -21; 42 21);

所以它有一個(gè)(0,-21)為(x,y),這意味著標(biāo)簽只出現(xiàn)在單元格邊界之外的某個(gè)地方。

所以我嘗試手動(dòng)添加調(diào)整框架,如下所示:

cell.testLabel.frame = CGRectMake(10,10,42,21)

可悲的是,它不起作用。

--------------- 10分鐘后更新-----------------

我做的。所以,似乎問(wèn)題來(lái)自Size Classes。

單擊.storyboard文件,然后轉(zhuǎn)到文件檢查器選項(xiàng)卡

取消勾選“大小類”復(fù)選框

最后,我的“太悲傷”的標(biāo)簽出來(lái)了!


查看完整回答
反對(duì) 回復(fù) 2019-08-27
  • 3 回答
  • 0 關(guān)注
  • 1177 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)