2016-10-23 4 views
0

ここで私が行ったことは:標準セルよりもはるかに大きく、青色の背景を持つペン先の大きなカスタムセルを作ったのです。このクラスここ標準のUITableViewCellがカスタムセルとオーバーラップします

enter image description here

されています:

import UIKit 

class CommonListViewCell: UITableViewCell { 
    @IBOutlet var background: UIView! 
    @IBOutlet var titleLabel: UILabel! 
    override func awakeFromNib() { 

     super.awakeFromNib() 
     titleLabel.font = UIFont(name: "roboto", size: titleLabel.font.pointSize) 
     NSLog("CommonListViewCell font changed") 
    }  
} 
ここにある

、CommonListViewCell.xibは

enter image description here

ここでは、適切なクラスに接続したスクリーンショットをです

ここでは、このテーブルビューを持っている私のViewControllerだ:

import UIKit 

class CommonListFragment: BaseFragment,UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate{ 


    @IBOutlet var lvMain: UITableView! 



    var prayerList = [PrayerDescription]() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.lvMain.delegate = self; 
     self.lvMain.dataSource = self; 
     self.lvMain.registerNib(UINib(nibName: "CommonListViewCell", bundle: nil), forCellReuseIdentifier: "commonlistidentifier") 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    convenience init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle? , listType type:Int) { 
     self.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) 
     switch type{ 
     case A.PRAYERS_TO_SAINTS: 
      prayerList = PrayerDescriptionEngine.saints 
      break 
     case A.CANNONS_AND_ACATHISTS: 
      prayerList = PrayerDescriptionEngine.acathistsAndCannons 
      break 
     default : 
      prayerList = PrayerDescriptionEngine.allPurpose 
      break 
     } 
    } 

    override func nightCheck() { 
     Utils.nightCheck([lvMain]) 
     lvMain.reloadData() 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 

     return prayerList.count 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("commonlistidentifier", forIndexPath: indexPath) as! CommonListViewCell 

     // Configure the cell... 
     cell.textLabel?.text = prayerList[indexPath.row].name 
     setLabelFont(cell.textLabel!) 
     Utils.nightCheck([cell.textLabel!]) 
     return cell 
    } 

    func scrollViewWillBeginDragging(scrollView: UIScrollView) { 
     parentVC.immedeateClose() 
    } 

    func tableView(tableView: UITableView, 
        didSelectRowAtIndexPath indexPath: NSIndexPath){ 
     parentVC.showActions(false) 
     NSLog("You selected cell #\(prayerList[ indexPath.row].resId)!") 
     let vc = AllPrayer(nibName :"AllPrayer", bundle: nil) 
     _=PrayerDescriptionEngine() 
     vc.setResId(prayerList[ indexPath.row].resId) 
     self.presentViewController(vc, animated: true, completion: nil) 
     tableView.deselectRowAtIndexPath(indexPath, animated: false) 
    } 



} 

そして、ここでは醜い結果である:

enter image description here

だから、私のカスタムテーブルのセルは、スタンダードセルの後ろには明らかです。何らかの理由で、標準セルにデータが正しく入力され、背面のカスタムセルに「ラベル」テキストが表示されます。カスタムセルは指定したサイズではありません。

ので、この1で私を助けてください - 私はXIB

+0

に動作します

希望。あなたのラベルは 'titleLabel'と呼ばれますので、あなたはそのラベルを使用する必要があります。 – dan

+0

@ダンありがとう!しかし、セルのサイズはまだ私のものではありません。それはまだ標準サイズです – user2976267

+0

@ user2976267 'Interface Builder'の' tableView'で変更されていないので、セルのサイズが異なります。あなたの 'tableView'は' 44pt 'というデフォルトのセルサイズを使用しています。 Xcodeの右側のパネルの 'Size Inspector'タブでそれを変更する必要があります。そして、テキストの長さに合わせてサイズを指定したい場合は、 'heightForRowAtIndexPath'メソッドを実装する必要があります。 – Adeel

答えて

0

に指定された私の色と私のサイズがstoryboradであなたのテーブルビューです持つ、テーブルビューで唯一の一つであることが私のカスタムセルを必要としますか? テーブルビューセルを選択し、IDインスペクタでカスタムセルクラスを認識させます。 tablviewdelegate方法で

enter image description here

1

、あなたがあなたのカスタムセルのcell.titlelabelにアクセスする必要がある一方で、現在のテーブルビューのcell.textlabelにアクセスrを。そして、あなたは細胞の背景色を設定している、それはそれがそれをオーバーラップさせる理由です。

現在のセル以外のカスタムセルのプロパティにアクセスする必要があります。 ので、

cell.titlelabel

cell.textlabelを交換し、カスタムセルをロードRなど持っていれば、ストーリーボードにテーブルビューのプロトタイプのセルを削除します。これはあなたが `UITableViewCell`基底クラスによって作成されたラベルであるセルの` textLabel`上のすべてのデータを設定している

関連する問題