UITableview
で、セクションと異なる行タイプ(shown here)で構成される画面を作成しようとしています。問題は、FrequencyセルのDetailラベルの値を変更しようとすると、get-onlyプロパティだと言います。フリークエンシーセルは、ストーリーボードに「Right Detail」と入力するように設定されています。UITableViewCellの詳細ラベルを設定できません
私のコードは次のとおりです。また
let frequencyCellID = "frequencyCell"
let decksCellID = "decksCell"
let pickerCellID = "pickerCell"
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell?
switch (indexPath.section,indexPath.row){
case (0,0): cell = tableView.dequeueReusableCellWithIdentifier(frequencyCellID)
//line below shows error
cell?.detailTextLabel? = "test"
case (0,1): cell = tableView.dequeueReusableCellWithIdentifier(pickerCellID)
case (1,0): cell = tableView.dequeueReusableCellWithIdentifier(decksCellID)
cell?.detailTextLabel? = "test"
default: break
}
return cell!
、どのように私は最後の行のセルをアンラップ力を避けることができますか?私は空のTableViewCellを初期化しようとしましたが、空の初期化子がないようです。
よろしいですか、テキストラベルの問題で間違いがあります。しかし、スイッチ内のindexpath引数に入れることをお勧めしますか? –
は 'tableView(tableView:UITableView、cellForRowAtIndexPath indexPath:NSIndexPath)'の引数として受け取ったindexPathを渡すだけです。最初のスイッチケースの行を 'cell = tableView.dequeueReusableCellWithReuseIdentifier(frequencyCellID、forIndexPath:indexPath)'に置き換えてコンパイルして実行します。 – xinatanil
ありがとう、ありがとう:) 私たちはそれを見ている間に、独自のクラスを持つピッカービューに基づいて詳細ラベルを更新したいと思います。 'pickerView:didSelectRow'で変更された' UITableView'か 'UIPickerView'の中にグローバル変数を作成すべきでしょうか? –