简体   繁体   English

是否可以同时为UIPickerView和UITableview设置动画

[英]Is it possible to animate a UIPickerView and a UITableview simultaneously

So currently I have UITableViewController that contains both a UITableView and an UIPickerView. 所以目前我有UITableViewController包含UITableView和UIPickerView。 The user can select how to filter the data in the table by using the picker. 用户可以使用选择器选择如何过滤表中的数据。 Currently, when the user scrolls over a row in the picker, the table is updated, this is how I accomplished this: 目前,当用户滚动选择器中的一行时,表格会更新,这就是我完成此操作的方法:

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

  // Code to update table data...

  self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation:UITableViewRowAnimation.Automatic)
  self.tableView.endUpdates()
  return title
}

Unfortunately, the table does not animate when reloadSections() is called. 不幸的是,当调用reloadSections()时,表没有动画。 My guess is that this is because I can't animate scrolling the picker and reloading the table at the same time. 我的猜测是因为我无法动画滚动选择器并同时重新加载表。

How would I go about animating both at the same time? 我如何同时进行动画制作? Thanks. 谢谢。

Basically, I think it could work fine. 基本上,我认为它可以正常工作。 I was using a snippet like this once, too and it didn't work either. 我曾经使用过一次这样的代码片段,它也没用。 As I recall I solved it by dragging an outlet of the UITableView to the ViewController and then calling 我记得我通过将UITableView的插座拖到ViewController然后调用来解决它

 @IBOutlet weak var myTableView: UITableView?

    ...


func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

  // Code to update table data...

  self.myTableView.reloadSections(NSIndexSet(index: 0), withRowAnimation:UITableViewRowAnimation.Automatic)
  self.myTableView.endUpdates()
  return title
}

...since self.tableView does not explicitly reference the UITableView you want it to reference. ...因为self.tableView没有显式引用您希望它引用的UITableView。 To check if it actually does - have you tried replacing 要检查它是否确实存在 - 您是否尝试过更换

self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation:UITableViewRowAnimation.Automatic)

with

self.tableView.reloadData()

?

Even if it possibly won't solve your problem, I hope this helps. 即使它可能无法解决您的问题,我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM