テーブルビューのセルをクリックして展開したり折りたたんだりしています。私はチュートリアルhttps://www.youtube.com/watch?v=LqHzHkuXRxQ&t=89sに従った。このビデオではすべてのものがまったく同じようになりました。エラーや警告なしで正常に実行されています。しかし、私はテーブルビューのセル内のコンテンツを見ることができませんでした。空のテーブルが表示されます。私はそれがXcodeのバージョンの問題だと思う。チュートリアルでは、彼はXcode 7を使用していました。私はXcode 8.2を使用しています。私は、テーブルビューのセル内のコンテンツを表示するために、私は何をすべきかわからない。Xcode 8.2でswift 3を使用してテーブルビューセルを展開したり折りたたんだりする際に問題が発生する
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var selectedIndex = -1
var dataArray : [[String:String]] = [["FirstName" : "Arun", "LastName" : "Gupta"],["FirstName" : "John", "LastName" : "Cena"],["FirstName" : "James" , "LastName" : "Bond"],["FirstName" : "Iron", "LastName" : "Man"]]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) ->CGFloat
{
if(selectedIndex == indexPath.row) {
return 100;
}
else{
return 40;
}
}
func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell{
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! customCell
let obj = dataArray[indexPath.row]
cell.firstViewLabel.text = obj["FirstName"]
cell.secondViewLabel.text = obj["LastName"]
return cell;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(selectedIndex == indexPath.row) {
selectedIndex = -1
} else {
selectedIndex = indexPath.row
}
self.tableView.beginUpdates()
self.tableView.reloadRows(at: [indexPath as IndexPath], with: UITableViewRowAnimation.automatic)
self.tableView.endUpdates()
}
}
import UIKit
class customCell: UITableViewCell {
@IBOutlet weak var firstView: UIView!
@IBOutlet weak var firstViewLabel: UILabel!
@IBOutlet weak var secondView: UIView!
@IBOutlet weak var secondViewLabel: UILabel!
@IBOutlet weak var secondHeightConstraint: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
var showsDetails = false {
didSet {
secondHeightConstraint.priority = showsDetails ? 250 : 999
}
}
}
https://github.com/jeantimex/ios-swift-collapsibleを使用するには、このリンクの簡単な方法を表題セクション –
サイトをありがとう。それも良いです。 –