2016-09-17 6 views
0

私は自分のプロジェクトで正常に実行されているtableViewを持っています。しかし、私は問題をcellviewと同じviewController.My textviewで私の長いtext私はセルを押したときにセルの選択を解除すると信じています。続くとしての私の部分のコード..テーブルビューdidSelect応答問題はSwiftで

注:私はissue..Iがわからないんで動作し、私の別のプロジェクトで以下のコードを使用しています いただきました。このテーブルビューで間違って....

おかげでアドバンス....

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let CellIdentifier: String = "fontCell" 
    let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath) 

    let fontName: String = self.fontName[indexPath.row] as! String 

    UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseInOut, animations: {() -> Void in 

    cell.textLabel?.text = fontName 
    cell.textLabel!.font = UIFont(name: self.fontName[indexPath.row] as! String, size: 25) 

    }, completion: nil) 

    cell.backgroundColor = UIColor.clearColor() 
    cell.textLabel?.textAlignment = .Center 
    cell.textLabel?.textColor = UIColor.whiteColor() 
    cell.textLabel?.sizeToFit() 
    cell.textLabel?.adjustsFontSizeToFitWidth = true 
    cell.selectionStyle = .Default 

    return cell 
} 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    //tableView.deselectRowAtIndexPath(indexPath, animated: true) 

    dispatch_async(dispatch_get_main_queue(), {() -> Void in 
    let fontName: String = self.fontName[indexPath.row] as! String 

    self.textView.font = UIFont(name: fontName, size: 20) 
    }) 

} 

答えて

1

didSelectRowAtIndexPathはまだdispatch_asyncを削除するメインスレッドで呼び出されなければなりませんし、ちょうどこのようなコードを実行すると、

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let fontName: String = self.fontName[indexPath.row] as! String 
    self.textView.font = UIFont(name: fontName, size: 20) 
} 
問題ないはずです

ジェスチャ認識機能をtableViewに追加して、他のタップを妨害しているかもしれない長い押しを処理した場合。 認識者のcancelsTouchesInViewをfalseに設定してみてください。

tapGestureRecognizer.cancelsTouchesInView = false 
+0

ありがとうございました。私はすでにあなたの解決策を試みました。しかし、私はdispatch_asyncを試してみました。私は何かが間違っていると思う私のtableviewコントローラの物理的な設定はまだわからない... – Joe

+0

didSelectRowAtIndexPathのコードは実行されますか?ブレークポイントを設定すると、行を選択すると停止しますか? – Moriya

+0

ありがとうございます。セル/長押しを押し続けるとコードが正常に機能します。しかし、私がセルを押すと、選択されたセルが選択されたままになり、選択したフィンガーセルが消えて、destビューが更新されなくなります... – Joe