2016-11-08 1 views
-1

スウィフトにiOSアプリがあります。私はカスタムテーブルビューを持っていて、私のセルにはボタンがあります(2つのボタンがありますが、1つは固定して、もう1つは固定できます)。ボタンをクリックすると、セルがある配列から別の配列に移動するはずですが、ここで問題となるのは、認識できないセレクタというアプリケーションがクラッシュするボタンをクリックしたときです。どんな助け?TableViewのスウィフトボタンクラッシュ

エラー:

CustomCellSwift[4834:1676038] -[CustomCellSwift.ViewController followButtonClick:]: unrecognized selector sent to instance 0x100b0b490 

フォローボタンコード:

// Follow Button 
@IBAction func followButtonClick(sender: UIButton!) { 

    // Adding row to tag 
    let buttonPosition = (sender as AnyObject).convert(CGPoint.zero, to: self.myTableView) 
    if let indexPath = self.myTableView.indexPathForRow(at: buttonPosition) { 

     // Showing Status Labels 
     let cell = self.myTableView.cellForRow(at: indexPath) as! CustomCell 
     cell.firstStatusLabel.isHidden = false 
     cell.secondStatusLabel.isHidden = false 

     // Change Follow to Following 
     (sender as UIButton).setImage(UIImage(named: "follow.png")!, for: .normal) 
     cell.followButton.isHidden = true 
     cell.followedButton.isHidden = false 
     self.myTableView.beginUpdates() 

     // ----- Inserting Cell to Section 0 ----- 
     followedArray.insert(testArray[indexPath.row], at: 0) 
     myTableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .fade) 

     // ----- Removing Cell from Section 1 ----- 
     testArray.remove(at: indexPath.row) 
     let rowToRemove = indexPath.row 
     self.myTableView.deleteRows(at: [IndexPath(row: rowToRemove, section: 1)], with: .fade) 

     self.myTableView.endUpdates() 

    } 
} 

移入細胞コード

func populateCell(_ testObject: Test, isFollowed: Bool, indexPath: IndexPath, parentView: Any) { 

    // Loading Background Color 
    self.backgroundColor = UIColor.white 

    // Loading Images -SDWebImage- *Crashes* 
    //let imgURL = (testObject.value(forKey: "testURL") as! String) // as! NSURL 
    //self.myImageView.contentMode = .scaleAspectFit 
    //self.myImageView.sd_setImage(with: imgURL as URL, placeholderImage: UIImage(named: "no-image.png")) // Missing RefreshCached 

    // Loading Status Labels 
    self.firstStatusLabel.text = testObject.testStatus1 
    self.secondStatusLabel.text = testObject.testStatus2 
    self.firstStatusLabel.isHidden = true 
    self.secondStatusLabel.isHidden = true 

    if isFollowed { 
     self.followedButton.tag = indexPath.row 
     self.followedButton.addTarget(parentView, action: Selector(("followedButtonClick:")), for: .touchUpInside) 
     self.followedButton.isHidden = false 
     self.followButton.isHidden = true 

     // Status Labels 
     self.firstStatusLabel.isHidden = false 
     self.secondStatusLabel.isHidden = false 

    } 
    else { 
     self.followButton.tag = indexPath.row 
     self.followButton.addTarget(parentView, action: Selector(("followButtonClick:")), for: .touchUpInside) 
     self.followedButton.isHidden = true 
     self.followButton.isHidden = false 

     // Status Labels 
     self.firstStatusLabel.isHidden = false // True when done testing 
     self.secondStatusLabel.isHidden = false // True when done testing 

    } 
} 
+0

をセルを挿入したり削除した後に追加および削除されている要素を確認してください、この配列を使用していますテーブルビューのセルに表示されます。あなたは、選択されているテーブルのセルに反応し、新しい配列に移動するfunc tableView(_ tableView:UITableView、didSelectRowAt indexPath:IndexPath)を使用することはできません? – MacUserT

+0

pinEditorまたはターゲットにアクションを追加する場合は、アクションfollowButtonClickに接続しているかどうかを確認してください。 –

+0

@MacUserTデザインがどういうものなのか – BroSimple

答えて

-1

馬セクション番号と行番号が正しいことを確認してください。位置が配列に見つからない場合もクラッシュします。

あなたは

1.followedArray

2.testArray

適切にボタンを置くのはなぜセル

+0

Objective-Cではすべてがうまくいっていましたが、Swiftに変換されましたが、今は動作しません – BroSimple

+0

コード内のswift 3.0のボタンにアクションを追加する構文を修正してください。 次のコードのようなアクションを追加します。myFirstButton.addTarget(self、action:#selector(myClass.pressed(_ :))、forControlEvents:.TouchUpInside) – Bucket

+0

私はiOSを初めて使ったので、このコードの違いは何ですか? – BroSimple