ここで私が行ったことは:標準セルよりもはるかに大きく、青色の背景を持つペン先の大きなカスタムセルを作ったのです。このクラスここ標準のUITableViewCellがカスタムセルとオーバーラップします
されています:
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は
ここでは、適切なクラスに接続したスクリーンショットをです
ここでは、このテーブルビューを持っている私の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)
}
}
そして、ここでは醜い結果である:
だから、私のカスタムテーブルのセルは、スタンダードセルの後ろには明らかです。何らかの理由で、標準セルにデータが正しく入力され、背面のカスタムセルに「ラベル」テキストが表示されます。カスタムセルは指定したサイズではありません。
ので、この1で私を助けてください - 私はXIB
に動作します
希望。あなたのラベルは 'titleLabel'と呼ばれますので、あなたはそのラベルを使用する必要があります。 – dan
@ダンありがとう!しかし、セルのサイズはまだ私のものではありません。それはまだ標準サイズです – user2976267
@ user2976267 'Interface Builder'の' tableView'で変更されていないので、セルのサイズが異なります。あなたの 'tableView'は' 44pt 'というデフォルトのセルサイズを使用しています。 Xcodeの右側のパネルの 'Size Inspector'タブでそれを変更する必要があります。そして、テキストの長さに合わせてサイズを指定したい場合は、 'heightForRowAtIndexPath'メソッドを実装する必要があります。 – Adeel