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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

拉風的咖菲貓 2019-08-27 15:31:07
在swift中創(chuàng)建自定義tableview單元我有一個帶有幾個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)     }}當我運行應用程序時,我的所有單元格都是空的。我已經(jīng)注銷self.venueService.mainCategoriesArray(),它包含所有正確的字符串。我也試過把一個實際的字符串等于標簽,這會產(chǎn)生相同的結果。我錯過了什么?任何幫助表示贊賞。
查看完整描述

3 回答

?
白衣非少年

TA貢獻1155條經(jīng)驗 獲得超0個贊

這適用于使用.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}


查看完整回答
反對 回復 2019-08-27
?
aluckdog

TA貢獻1847條經(jīng)驗 獲得超7個贊

我也有同樣的問題。

一般來說,我做的和你一樣。

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什么都沒顯示!但是猜猜看,它實際上顯示了一些東西......因為我從println(cell.testLabel)獲得的日志顯示所有標簽實際上都顯示出來了。

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

frame =(0 -21; 42 21);

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

所以我嘗試手動添加調整框架,如下所示:

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

可悲的是,它不起作用。

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

我做的。所以,似乎問題來自Size Classes。

單擊.storyboard文件,然后轉到文件檢查器選項卡

取消勾選“大小類”復選框

最后,我的“太悲傷”的標簽出來了!


查看完整回答
反對 回復 2019-08-27
  • 3 回答
  • 0 關注
  • 1183 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號