MKRViewController.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // MKRViewController.m
  3. // MKRRadioManager
  4. //
  5. // Created by yyqxiaoyin on 04/15/2019.
  6. // Copyright (c) 2019 yyqxiaoyin. All rights reserved.
  7. //
  8. #import "MKRViewController.h"
  9. #import "MKRPlayControlViewController.h"
  10. #import <MKRRadioManager/MKRAVPlayer.h>
  11. #import <YYCategory/NSString+Utilities.h>
  12. #import <NSHashTable+MKRRadioManagerAdd.h>
  13. #import "MKRTestObject.h"
  14. @interface MKRViewController ()
  15. @property (nonatomic, strong)UITableView *tableView;
  16. @property (nonatomic, strong)NSMutableArray *dataSource;
  17. @property (nonatomic, strong) MKRAVPlayer *player;
  18. @property (nonatomic, strong) NSHashTable *hashTable;
  19. @property (nonatomic, strong) NSMutableArray *array;
  20. @end
  21. @implementation MKRViewController
  22. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  23. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  24. [self.hashTable makeObjectsPerformSelectorWithObjectsOnMainThread:@selector(testMethod:),@"hello"];
  25. });
  26. }
  27. - (IBAction)refresh:(UIBarButtonItem *)sender {
  28. [self.dataSource removeAllObjects];
  29. [self searchDevice];
  30. }
  31. - (void)searchDevice{
  32. [_MKRWIFIDeviceManager searchDeviceWithSearchTime:20 timeBlock:^(NSInteger time) {
  33. [self.tableView reloadData];
  34. }];
  35. }
  36. - (void)viewDidLoad
  37. {
  38. [super viewDidLoad];
  39. for (NSInteger i = 0; i<10; i++) {
  40. MKRTestObject *obj = [[MKRTestObject alloc] init];
  41. [self.array addObject:obj];
  42. [self.hashTable addObject:obj];
  43. }
  44. }
  45. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  46. return self.dataSource.count;
  47. }
  48. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  49. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  50. MKRUPnPDevice *device = self.dataSource[indexPath.row];
  51. cell.textLabel.text = device.deviceName;
  52. return cell;
  53. }
  54. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  55. MKRPlayControlViewController *vc = [[MKRPlayControlViewController alloc] initWithDevice:self.dataSource[indexPath.row]];
  56. [self.navigationController pushViewController:vc animated:YES];
  57. }
  58. - (void)testMethod{
  59. MKRLog(@"测试方法");
  60. }
  61. - (NSMutableArray *)dataSource {
  62. if (!_dataSource) {
  63. _dataSource = [NSMutableArray array];
  64. }
  65. return _dataSource;
  66. }
  67. - (NSHashTable *)hashTable{
  68. if (!_hashTable) {
  69. _hashTable = [NSHashTable weakObjectsHashTable];
  70. }
  71. return _hashTable;
  72. }
  73. - (NSMutableArray *)array{
  74. if (!_array) {
  75. _array = [NSMutableArray array];
  76. }
  77. return _array;
  78. }
  79. @end