Xcode 9.3
Swift 4.1
Swift初心者です。
UITableViewCell
にカスタムクラスをつくり、タップしたら編集できるような機能を作りたいのですが、起動するとsignal SIGABT
が出て起動を完了することができません。
(ビルドはでき、LaunchScreen.storyboard
からMain.storyboard
に遷移する際にSIGABT
が発生します)
参考にしたのは次のサイトで、Swiftのバージョン違いによる変更の他はそのままです。
【Xcode】文字入力できるTableViewCellサンプル
Swift
1// ViewController.swift 2 3import UIKit 4 5class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, InputTextTableCellDelegate { 6 7 @IBOutlet weak var tableView: UITableView! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 } 11 12 override func didReceiveMemoryWarning() { 13 super.didReceiveMemoryWarning() 14 } 15 16//MARK: - UITableVIewDataSource 17 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 18 return 10 19 } 20 21 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 22 //22・23行目: ここでsignal SIGABTが発生する 23 let cell: InputTextTableCell = tableView.dequeueReusableCell(withIdentifier: "todoCell", for: indexPath) as! InputTextTableCell 24 cell.delegate = self 25 //24行目: 22・23行目をコメントアウト、24行目をコメントインすると起動できる 26// let cell = tableView.dequeueReusableCell(withIdentifier: "todoCell", for: indexPath) 27 return cell 28 } 29 30//MARK: - UITableViewDelegate 31 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 32 return InputTextTableCell.height() 33 } 34 35 func textFieldDidEndEditing(cell: InputTextTableCell, value: NSString) -> () { 36 let path = tableView.indexPathForRow(at: cell.convert(cell.bounds.origin, to: tableView)) 37 NSLog("row = %d, value = %@", path!.row, value) 38 } 39}
Swift
1// InputTextTableCell.swift 2 3import UIKit 4 5protocol InputTextTableCellDelegate { 6 func textFieldDidEndEditing(cell: InputTextTableCell, value: NSString) -> () 7} 8 9class InputTextTableCell: UITableViewCell, UITextFieldDelegate { 10 var delegate: InputTextTableCellDelegate! = nil 11 12 override func awakeFromNib() { 13 super.awakeFromNib() 14 } 15 16 override func setSelected(_ selected: Bool, animated: Bool) { 17 super.setSelected(selected, animated: animated) 18 } 19 20 static func height() -> CGFloat { 21 return 75.0 22 } 23 24// MARK: - UITextFieldDelegate 25 internal func textFieldShouldReturn(_ textField: UITextField) -> Bool { 26 textField.resignFirstResponder() 27 return true 28 } 29 30 internal func textFieldDidEndEditing(_ textField: UITextField) { 31 self.delegate.textFieldDidEndEditing(cell: self, value: textField.text! as NSString) 32 } 33} 34
ViewControllerの22行目でSIGABTが発生しています。
22,23行目をコメントアウトしてカスタムクラスの使用を取りやめ、
24行目をコメントインして通常のUITableViewCellを使用するとSIGABTはなくなり、起動することができます。
なので、tableViewのoutlet接続、UITableViewCellのidentiferはちゃんと設定できているのだと思うのですが…。
SIGABTを解決する糸口だけでも見つけられないでしょうか。
お知恵を拝借できますと幸いです。
どうぞよろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/11 22:12