1

UITableViewiOS8 のカスタム キーボードにを追加しようとしています。キーボードにはストーリーボードのようなインターフェイス ファイルがないため、プログラムで追加する必要がありますが、UITableView表示されません。私はこれをやっています
viewDidLoad

self.tableView = UITableView(frame: CGRectMake(0, 0, view.frame.width, view.frame.height), style: UITableViewStyle.Plain)
tableView.delegate = self;
tableView.dataSource = self;
self.view.addSubview(self.tableView)
tableView.reloadData()

次に、実装numberOfSectionsInTableViewnumberOfRowsInSectioncellForRowAtIndexPathメソッドでこれを行っています:

        var cell = tableView.dequeueReusableCellWithIdentifier("CopyCell", forIndexPath: indexPath) as UITableViewCell
    if let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("CopyCell", forIndexPath: indexPath) as? UITableViewCell {
        cell.textLabel!.text = "Hello World"
        cell.backgroundColor = UIColor.redColor()
    }else{
        cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CopyCell")
        cell.textLabel!.text = "Hello World"
        cell.backgroundColor = UIColor.redColor()
    }
    return cell

重要な詳細を見逃したかどうかはわかりませんが、テーブル ビューはカスタム キーボードに表示されません。それを示すために、背景とセルの色を追加しました。

4

2 に答える 2

0

UITableView は XIB でのみ使用できますが、プログラムで追加することはできません。

于 2014-10-22T19:16:48.033 に答える