UITableViewの場合、2つの異なるセルのいずれかを使用しています。最初のものは内容を表示し、2番目のものは配列が空の場合に内容がないという簡単なラベルです。私はまた、どのアレイを使用するかを制御するセグメント化されたコントローラを切り替えています。私は両方の細胞のためのクラスを持っています。 2番目のラベルには、セグメント化されたコントローラに基づいて変更されるIBoutletがあります。私のコードは次のようになります:異なるセルを返すUITableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnValue = 0
switch(mySegmentedControl.selectedSegmentIndex) {
case 0:
returnValue = accounts.count
break
case 1:
returnValue = user.count
break
case 2:
returnValue = mutual.count
default:
break
}
return returnValue
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ConnectCell", for: indexPath) as! ConnectTableViewCell
let cell2 = tableView.dequeueReusableCell(withIdentifier: "noUsersCell") as! NoUsersTableViewCell
switch(mySegmentedControl.selectedSegmentIndex) {
case 0:
let user = self.accounts[indexPath.row]
cell.user = user
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.delegate = self
break
case 1:
let user = self.user[indexPath.row]
cell.user = user
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.delegate = self
break
case 2:
let user = self.mutual[indexPath.row]
cell.user = user
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.delegate = self
break
default:
break
}
return cell
}
これまでのところ、これは新しい機能であるため、「cell2」を追加しました。私はnumberOfRowsInSectionを使って配列が空であるかどうかをチェックし、空であれば1を返し、CellForRowAtの場合に条件を入れて配列が空であるかどうかを調べ、cell2を使う必要があると考えます。次に、cell2のテキストを変更することができます。しかし、私は休憩の後に単一のcell2を返す方法を知らない。何か案は?
を行う必要があります - これはスウィフトあります。あなたの 'case'ステートメントに' break'ステートメントは必要ありません。 – rmaddy