ios - 从可重用的 UITableViewCell 对象开始视频播放

标签 ios objective-c uitableview

我在 storyboard 中设置了一个 TableView 并有一个用于保存图像的原型(prototype)单元格和一个用于启动视频的按钮。视频文件的路径是每个单元格对象中的一个属性,我想在单击按钮时播放视频。

在我开始使用表格之前(当我刚刚在 Storyboard上手动绘制按钮时)我使用以下命令启动电影播放器​​ [self presentMoviePlayerViewControllerAnimated:mp]; 但显然现在这是不可能的.

我确定我遗漏了一些明显的东西......

最佳答案

最好的解决方案是NSNotificationCenter。单击时,在单元格中只需发送带有行索引的通知,您可以将其保存在按钮的标记变量中。

    NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:@"playVideo" forKey:@"operationKey"];

   [userInfo setValue: indexPath forKey:@"indexPathRow"];


   [[NSNotificationCenter defaultCenter] postNotificationName: @"PlayVideoNotification" object:nil userInfo:userInfo];

在您的 ViewController 中注册观察者:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivePlayVideoNotification:) name:@"PlayVideoNotification" object:nil];

并且不要忘记注销观察者:

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PlayVideoNotification" object:nil];

在方法PlayVideoNotification中执行您需要的操作:

- (void) receivePlayVideoNotification:(NSNotification *) notification
{

  NSDictionary *userInfo = notification.userInfo;
  NSString *operationKey = [userInfo objectForKey:@"operationKey"];//"playVideo"
  NSString* indexPathRow = [userInfo objectForKey:@"indexPathRow"];  

  //todo

}

关于ios - 从可重用的 UITableViewCell 对象开始视频播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382161/

相关文章:

ios - 自定义注释中以编程方式按钮

iphone - hitTest:WithEvent 和 subview

ios - 在 Xcode 的 Storyboard中使用另一个 UIView 创建和加载 View

ios - 键盘出现时如何滚动 UIScrollView?

ios - 如何确定自定义 UITableViewCell 中的按钮单击?

ios - 关闭压缩单元格背景图像 - Objective-C (Xcode)

ios - Swift 3 转换错误/NSError

ios - 如何使用 ARKit 打开/关闭相机闪光灯?

ios - 是否可以在一个 UiTableView 中有两个不同的 UiTableViewCell?

ios - Facebook App Invites iOS SDK v4.0 配置和状态