2017-11-21 11 views
0

私は、storyboardsを使用してUIView内に配置したUITableViewにnibファイルをロードしようとしています。認識できないセレクタ/接続するビューコントローラ

UITableViewとUIViewには2つの独立したViewControllerがあり、それらを接続しようとしていますが、認識できないセレクタというエラーメッセージが表示されます。これは何を意味するのでしょうか?

ありがとうございました!

VC1

class CreateMeetPlanning: CreateMeet { 

@IBOutlet var tableView: TableViewPlanning! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    } 

@IBAction func closePlanning(_ sender: UIButton) { 
    dismiss(animated: true, completion: nil) 
} 

//Automatically open keyboard 
//override func viewDidAppear(_ animated: Bool) { 
    //super.viewDidAppear(animated) 
    //planningRow.becomeFirstResponder() 
//} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


/* 
// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
*/ 

} 

VC2

class TableViewPlanning: UITableViewController, UITextFieldDelegate { 

// forcing status bar to hide 
override var prefersStatusBarHidden: Bool { 
    return true 
} 

// properties 
var todo: Array<String> = [""] 
var defTodo: Array<String> = [""] 


// selecting textfield in first empty row 

func responder() { 
    self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .none, animated: false) 
    if let cell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? TableViewCell { 
     cell.textField.becomeFirstResponder() 
    } 
} 


// saving data to UserDefaults 
func save() { 
    let defaults = UserDefaults.standard 
    defaults.set(self.todo, forKey: "todo") 
} 

// retrieving data from UserDefaults 
func get() { 
    let defaults = UserDefaults.standard 
    self.todo = defaults.stringArray(forKey: "todo") ?? [""] 
    tableView.reloadData() 
} 


// action on tapping "Done" on a keyboard 

func textFieldShouldReturn(_ textField: UITextField) -> Bool { 
    let task = textField.text ?? " " 
    let indexPath = self.tableView.indexPathForView(textField) 
    if indexPath?.row == 0 { 
     self.todo.insert(task, at: 1) 
     print(self.todo) 
     tableView.beginUpdates() 
     self.tableView.insertRows(at: [indexPath!], with: .top) 
     tableView.endUpdates() 
    } 
    else { 
     self.todo[indexPath!.row] = task 
     tableView.reloadData() 

    } 
    responder() 
    save() 
    return true 
} 

// TABLEVIEW methods 
// amount of rows 
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return self.todo.count 
} 

// content for the row 
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell 
    cell.textField.delegate = self 
    cell.textField.text = self.todo[indexPath.row].description 
    // cell.textField.becomeFirstResponder() 
    return cell 
} 

// deleting rows: all rows to be deleted if first row is deleted, others as usual. 
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) 
{ 
    if indexPath.row != 0 { 
     if editingStyle == .delete 
     { 
      self.todo.remove(at: indexPath.row) 
      tableView.beginUpdates() 
      tableView.deleteRows(at: [indexPath], with: .automatic) 
      tableView.endUpdates() 
     } 
    } 
    else { if editingStyle == .delete 
    { 
     self.todo = self.defTodo 
     tableView.reloadData() 
     } 
    } 
    print(self.todo) 
    responder() 

    save() 
} 

@objc func refresh(refresh: UIRefreshControl) { 
    refresh.endRefreshing() 
    responder() 
} 

// ViewController life-cycle 
override func viewDidLoad() { 
    super.viewDidLoad() 
    let nib = UINib(nibName: "TableViewCell", bundle: nil) 
    tableView.register(nib, forCellReuseIdentifier: "Cell") 
    get() 
    refreshControl = UIRefreshControl() 
    refreshControl?.attributedTitle = NSAttributedString(string: "") 
    refreshControl?.addTarget(self, action: #selector(refresh(refresh:)), for: .valueChanged) 
    refreshControl?.tintColor = UIColor.red 
    tableView.refreshControl = refreshControl 
    responder() 
} 

override func viewDidAppear(_ animated: Bool) { 
} 
} 

ERROR

 
2017-11-21 17:48:15.599430+0100 meetIOS[416:43942] [MC] Lazy loading NSBundle MobileCoreServices.framework 
2017-11-21 17:48:15.601629+0100 meetIOS[416:43942] [MC] Loaded MobileCoreServices.framework 
2017-11-21 17:48:15.631201+0100 meetIOS[416:43942] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 
2017-11-21 17:48:15.797665+0100 meetIOS[416:43942] refreshPreferences: HangTracerEnabled: 0 
2017-11-21 17:48:15.797774+0100 meetIOS[416:43942] refreshPreferences: HangTracerDuration: 500 
2017-11-21 17:48:15.797820+0100 meetIOS[416:43942] refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0 
2017-11-21 17:48:17.744420+0100 meetIOS[416:43942] -[meetIOS.TableViewPlanning superview]: unrecognized selector sent to instance 0x101d1a9f0 
2017-11-21 17:48:17.746086+0100 meetIOS[416:43942] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[meetIOS.TableViewPlanning superview]: unrecognized selector sent to instance 0x101d1a9f0' 
*** First throw call stack: 
(0x182bd5d04 0x181e24528 0x182be31c8 0x18c3cb110 0x182bdb6b0 0x182ac101c 0x18c014074 0x18c2dc5ec 0x18c747160 0x18c7472d8 0x18c746e98 0x18c2dc57c 0x18c747160 0x18c746e98 0x18c59c0cc 0x18c747160 0x18c7472d8 0x18c746e98 0x18c59b40c 0x18c37b17c 0x18c12aee4 0x18c00cba4 0x18c00cad4 0x18c38ac04 0x18c383a2c 0x18c385428 0x18c387ccc 0x18c388200 0x18c387c1c 0x18c0ebaa8 0x18c910038 0x18c92ab30 0x18c92a9d4 0x18c92aca8 0x18c041608 0x18c041588 0x18c02c2f0 0x18c040e7c 0x18c04099c 0x18c03be6c 0x18c00d378 0x18c95a85c 0x18c95cde8 0x18c955d04 0x182b7e2e8 0x182b7e268 0x182b7daf0 0x182b7b6c8 0x182a9bfb8 0x184933f84 0x18c0702e8 0x100948e14 0x1825be56c) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 
+0

関連コードを投稿してください。エラーを引き起こすコードの正確な行を明確に指摘してください。 – rmaddy

+0

ありがとう、編集されます。 – Tomas

+0

すべてのコードを削除したのはなぜですか?私はあなたが関係するコードを投稿して、実際にあなたのエラーの原因となっているコード行を指摘しなければならないということを意味しました。 – rmaddy

答えて

0

は問題はおそらくあなたがCreateMeetPlanning VCを持っているストーリーボードであり、あなたが割り当てられているのtableViewを持っていますアウトレットtableView: TableViewPlanning!。しかしTableViewPlanningはUITableViewではなく、UITableViewControllerです。したがって、クラッシュ。

コンセプトをstorybardで使用してUITabelviewcontrollerを埋め込み、コンセントに接続する前にそのクラスをTableViewPlanningに変更する必要があります。これと同じようなことがanswerで行われました。

+1

ありがとう、それを試してみよう! – Tomas

+0

これはうまくいきました、ありがとう! – Tomas

+0

喜んで助けてください。乾杯!! –

関連する問題