が
let indexPath = tableView.indexPathForSelectedRow();
var sectionNumber = indexPath.section
であり、0ショーはように最初のラベルを更新しているかどうかを確認しかし、私は、インデックスの行のためのセルで最高の場所だと思いますし、
そこのラベル更新しセクション番号を取得します別の解決策
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//Create label and autoresize it
let headerLabel = UILabel(frame: CGRectMake(0, 0, tableView.frame.width, 2000))
headerLabel.font = UIFont(name: "Avenir-Light", size: 30)
headerLabel.text = self.tableView(self.tableView, titleForHeaderInSection: section)
headerLabel.sizeToFit()
//Adding Label to existing headerView
let headerView = UIView()
headerView.addSubview(headerLabel)
return headerView
}
もこの
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
{
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font = UIFont(name: "Futura", size: 11)
header.textLabel?.textColor = UIColor.lightGrayColor()
}
012を試しています
これはヘッダーに関するものではありません。私は単一のラベルで質問を単純化したいと思っていましたが、実際には、画像があり、ユーザーが正しいセクションにいる場合にイメージを変更する必要があるボタンが約12あります。あなたがセクション0にいる場合、ボタンは "emoji-unselected"から "emoji-selected"になります。セクション1では、「選択されていない動物」から「動物が選択された」などになります。 – VDog
@VDogそれはユーザーが「正しいセクションにある」ということを意味します。複数のセクションは、通常、同時に画面上に表示することができます。私は個人的に 'collectionView(_ collectionView:UICollectionView、willDisplayセル:UICollectionViewCell、forItemAt indexPath:IndexPath)'を使用して、インデックスパスのセクションをチェックしようとしていますが、それはかなり粗いです。 .indexPathsForVisibleItems'を実行すると、どのセクションがどれくらいあるかを確認できます。 –