2017-10-21 5 views
0

ActivityIndicatorViewをそれぞれUITableViewCellに入れ、タップ後にアニメーションを開始してアクションが進行中であることを確認します。しかし、私はアニメーション効果を開始することはできません。iOS:UITableViewCell内のアクティビティインジケータを使用できません

ActivityIndicatorViewをセルプロトタイプに追加し、@IBOutletで接続しました。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

     let selectedAction = actions[indexPath.row] 

     let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", for: indexPath) as! ActionTableViewCell 

     cell.activityInProgressIndicator.startAnimating() 

    } 

私もcell.accessoryViewとしてActivityIndicatorViewの新しいインスタンスを追加してみました:これは、ユーザーがテーブルの行を選択した後、アニメーションを開始するために私のコードです。効果なし。

私はまた、理想的には、このスピニングインジケータが隠されるべきでなく、didSelectRowAt.isHidden = falseを設定すると動作しません

tableView.reloadData()(私は避けたいもの)とtableView.beginUpdates()経由とtableView.endUpdates()いずれかのセルを更新しようとしました。

+0

インジケーターが表示されますか?ちょうどそれを開始するために問題ですか? –

+0

@ Milanいいえ、isHiddenをtrueに設定しないと、インジケータが表示されます。 – Filip

答えて

2

tableView.dequeueReusableCelldidSelectRowAtの中に使用すると、新しいインスタンスがActionTableViewCellに作成されるという問題があります。これは間違っています。 次のようなものを使用する必要があります。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    guard let cell = tableView.cellForRow(at: indexPath) as? ActionTableViewCell else { return } 
    cell.activityInProgressIndicator.startAnimating() 
} 

これで問題が解決します。ただ、

let cell = tableView.dequeueReusableCell(withIdentifier: "actionCell", 
for: indexPath) as! ActionTableViewCell with below line 

let cell = tableView.cellForRow(at: indexPath) as! ActionTableViewCell. 

を交換

3

は、それが動作しますホープ!

関連する問題