首記の件ですが、UITableVIew+CustomCellを使って
レイアウトを行っているのですが、CustomCell内に設置した
UILabelのtextが表示されずに困っています。
どこに原因がありますでしょうか?
何卒ご教授のほどよろしくお願いいたします。
Swift
1class ViewController:UIViewController, UITableViewDataSource, UITableViewDelegate{ 2 3 var tableView : UITableView! 4 //customCellのUILabelのtext用Array 5 let titleArray = [ 6 "テストテストテスト・テストテスト", 7 "テストテストテスト・テストテスト", 8 "テストテストテスト・テストテスト", 9 "テストテストテストテストテストテスト", 10 "テスト", 11 "テスト" 12 ] 13 14 override func viewDidLoad() { 15 super.viewDidLoad() 16 17 tableView = UITableView() 18 tableView = UITableView(frame: CGRect(x: 0, y: 0, width: self.view.layer.bounds.width, height: self.view.layer.bounds.height)) 19 tableView.registerClass(CustomCell.self, forCellReuseIdentifier: "customCell") 20 tableView.delegate = self 21 tableView.dataSource = self 22 self.view.addSubview(tableView) 23 } 24 25 func numberOfSectionsInTableView(tableView: UITableView) -> Int { 26 return 1 27 } 28 29 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 30 return titleArray.count 31 } 32 33 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 34 return 100 35 } 36 37 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell { 38 39 //cell deque 40 let cell: customCell = tableView.dequeueReusableCellWithIdentifier("customCell") as! CustomCell 41 42 //セルの中身を表示 43 cell.setupContents( 44 titleArray[indexPath.row] 45 ) 46 47 return cell 48 } 49 50}
↓Custom Cell
Swift
1class CustomCell:UITableViewCell{ 2 3 var titles = UILabel() 4 5 required init?(coder aDecoder: NSCoder) { 6 super.init(coder: aDecoder) 7 } 8 9 override func awakeFromNib() { 10 super.awakeFromNib() 11 } 12 13 override init(style: UITableViewCellStyle, reuseIdentifier: String!) { 14 super.init(style: style, reuseIdentifier: reuseIdentifier) 15 16 setupView() 17 18 } 19 20 // ビューの作成と設定 21 func setupView(){ 22 23 let screenWidth:CGFloat = self.bounds.width 24 let titleWidth:CGFloat = screenWidth - 20 25 26 titles.frame = CGRectMake((screenWidth - titleWidth)/2, 10, titleWidth, 0) 27 titles.font = UIFont(name: "Helvetica Neue", size: 14) 28 titles.numberOfLines = 0 29 titles.lineBreakMode = NSLineBreakMode.ByCharWrapping 30 titles.sizeToFit() 31 let titleHeight:CGFloat = self.titles.frame.size.height 32 titles.frame = CGRectMake((screenWidth - titleWidth)/2, videoPlayerHeight + spotContainerHeight + 10, titleWidth, titleHeight) 33 self.addSubview(titles) 34 } 35 36 // cell内コンテンツ表示 37 func setupContents(title:String){ 38 titles.text = title 39 } 40 41}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/22 06:55
2015/10/23 01:03
2015/11/03 14:36
2015/11/04 01:30