1
私は1つのUIPickerViewと1つのラベルを展開可能なUITableViewCellに入れています。コードでは、1つのセクションと3つのセルをすべて最初のセルのようにしました。同じUIPickerViewを異なるデータで複数回使用するには? - Swift
私はすべてのセルのデータを管理しましたが、問題は最初のピッカーから何かを選択して2番目のピッカーに移動して何かを選択すると、2番目のピッカーから同じ行の順序に変更されます。
は、私は3つのピッカーが互いに分離することができますどのようにそれを短くすると、これは私のビューへのスクリーンショットである
ない他の同一の細胞から選択された行にすべてのセルのラベルを変更するには:
import UIKit
let cellID = "cell"
class callViewController: UITableViewController {
var selectedIndexPath : NSIndexPath?
var tapped = false // when the first cell tapped it will be true
var flag = true
// These strings will be the data for the table view cells
let sections: [String] = ["Department:", "Team:", "Service:"]
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
//number of sections
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
// header for the secation
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Required Info:"
}
//number of rows in section
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
//get the cell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) as! callCustomCell
cell.titleLabel.text=self.sections[indexPath.row]
// now reload the appropriate pickerData
if indexPath.row == 0{
cell.inputArrry=cell.departments
cell.picker.reloadAllComponents()
}
else if indexPath.row == 1{
cell.inputArrry=cell.teams
cell.picker.reloadAllComponents()
}
else if indexPath.row == 2{
cell.inputArrry=cell.services
cell.picker.reloadAllComponents()
}
if indexPath.row != 0{
cell.userInteractionEnabled = tapped
if (!tapped){
cell.backgroundColor=UIColor.clearColor()
}
else {
cell.backgroundColor=UIColor.whiteColor()
}
}
if indexPath.row==0{
cell.backgroundColor=UIColor.whiteColor()
cell.userInteractionEnabled=true
}
return cell
}
// method to run when table view cell is tapped
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 && flag {
flag = false
tapped = true
tableView.reloadRowsAtIndexPaths([
NSIndexPath(forRow: 1, inSection: 0),
NSIndexPath(forRow: 2, inSection: 0)], withRowAnimation: .Automatic)
}
let previousIndexPath = selectedIndexPath
if indexPath == selectedIndexPath {
selectedIndexPath = nil
}
else {
selectedIndexPath = indexPath
}
var indexPaths : Array<NSIndexPath> = []
if let previous = previousIndexPath {
indexPaths += [previous]
}
if let current = selectedIndexPath {
indexPaths += [current]
}
if indexPaths.count > 0 {
tableView.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! callCustomCell).watchFrameChanges()
}
override func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! callCustomCell).ignoreFrameChanges()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
for cell in tableView.visibleCells as! [callCustomCell] {
cell.ignoreFrameChanges()
}
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath == selectedIndexPath {
return callCustomCell.expandedHeight
} else {
return callCustomCell.defaultHeight
}
}
}
'cell.picker.reloadAllComponents() 'を呼び出すときに、各ピッカーの状態を保存して、選択したコンポーネントをリセットする必要があると思います。 – Grimxn
@Grimxnユーザーが選択した選択肢を保存するかもしれませんが、他のピッカーのセクションを変更した場合のピッカーの選択の変更?または選択肢の横のようなピッカーの状態を教えてもらえますか?ありがとうございます。 – Zizoo
このライブラリを使用してみてください。異なるモード文字列、日付と時刻のピッカーが表示されます。表示する場合は、ユーザーの選択を処理する完了ハンドラが必要です。https://github.com/skywinder/ActionSheetPicker-3.0 –