VLCLocalServerListViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*****************************************************************************
  2. * VLCLocalServerListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2014 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre SAGASPE <pierre.sagaspe # me.com>
  10. * Gleb Pinigin <gpinigin # gmail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCLocalServerListViewController.h"
  15. #import "UIBarButtonItem+Theme.h"
  16. #import "VLCAppDelegate.h"
  17. #import "UPnPManager.h"
  18. #import "VLCLocalNetworkListCell.h"
  19. #import "VLCLocalServerFolderListViewController.h"
  20. #import <QuartzCore/QuartzCore.h>
  21. #import "GHRevealViewController.h"
  22. #import "VLCNetworkLoginViewController.h"
  23. #import "UINavigationController+Theme.h"
  24. #import "VLCPlaylistViewController.h"
  25. #import "Reachability.h"
  26. @interface VLCLocalServerListViewController () <UITableViewDataSource, UITableViewDelegate, NSNetServiceBrowserDelegate, VLCNetworkLoginViewController, NSNetServiceDelegate, VLCMediaListDelegate, UPnPDBObserver>
  27. {
  28. UIBarButtonItem *_backToMenuButton;
  29. NSArray *_sectionHeaderTexts;
  30. NSNetServiceBrowser *_ftpNetServiceBrowser;
  31. NSMutableArray *_rawNetServices;
  32. NSMutableArray *_ftpServices;
  33. NSArray *_filteredUPNPDevices;
  34. NSArray *_UPNPdevices;
  35. VLCMediaDiscoverer * _sapDiscoverer;
  36. VLCNetworkLoginViewController *_loginViewController;
  37. UIRefreshControl *_refreshControl;
  38. UIActivityIndicatorView *_activityIndicator;
  39. Reachability *_reachability;
  40. BOOL _udnpDiscoveryRunning;
  41. NSTimer *_searchTimer;
  42. }
  43. @end
  44. @implementation VLCLocalServerListViewController
  45. - (void)dealloc
  46. {
  47. [_reachability stopNotifier];
  48. [_ftpNetServiceBrowser stop];
  49. }
  50. - (void)loadView
  51. {
  52. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  53. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  54. _tableView.delegate = self;
  55. _tableView.dataSource = self;
  56. self.view = _tableView;
  57. _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  58. _activityIndicator.center = _tableView.center;
  59. _activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  60. _activityIndicator.hidesWhenStopped = YES;
  61. [self.view addSubview:_activityIndicator];
  62. }
  63. - (void)viewDidLoad
  64. {
  65. [super viewDidLoad];
  66. /* if (SYSTEM_RUNS_IOS7_OR_LATER)
  67. _sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)", @"Network Streams (SAP)"];
  68. else*/
  69. _sectionHeaderTexts = @[@"Universal Plug'n'Play (UPNP)", @"File Transfer Protocol (FTP)"];
  70. _backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
  71. self.navigationItem.leftBarButtonItem = _backToMenuButton;
  72. self.tableView.rowHeight = [VLCLocalNetworkListCell heightOfCell];
  73. self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  74. self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  75. self.title = NSLocalizedString(@"LOCAL_NETWORK", @"");
  76. _ftpServices = [[NSMutableArray alloc] init];
  77. [_ftpServices addObject:NSLocalizedString(@"CONNECT_TO_SERVER", nil)];
  78. _rawNetServices = [[NSMutableArray alloc] init];
  79. _ftpNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
  80. _ftpNetServiceBrowser.delegate = self;
  81. _refreshControl = [[UIRefreshControl alloc] init];
  82. [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
  83. [self.tableView addSubview:_refreshControl];
  84. if (SYSTEM_RUNS_IOS7_OR_LATER)
  85. _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCFutureNetworkLoginViewController" bundle:nil];
  86. else
  87. _loginViewController = [[VLCNetworkLoginViewController alloc] initWithNibName:@"VLCNetworkLoginViewController" bundle:nil];
  88. _loginViewController.delegate = self;
  89. _reachability = [Reachability reachabilityForLocalWiFi];
  90. [_reachability startNotifier];
  91. [self netReachabilityChanged:nil];
  92. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
  93. }
  94. - (void)viewWillDisappear:(BOOL)animated
  95. {
  96. [super viewWillDisappear:animated];
  97. [_activityIndicator stopAnimating];
  98. [_ftpNetServiceBrowser stop];
  99. }
  100. - (void)viewWillAppear:(BOOL)animated
  101. {
  102. [_ftpNetServiceBrowser searchForServicesOfType:@"_ftp._tcp." inDomain:@""];
  103. [_activityIndicator stopAnimating];
  104. [super viewWillAppear:animated];
  105. [self netReachabilityChanged:nil];
  106. }
  107. - (void)netReachabilityChanged:(NSNotification *)notification
  108. {
  109. if (_reachability.currentReachabilityStatus == ReachableViaWiFi) {
  110. [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
  111. [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
  112. } else {
  113. [self _stopUPNPDiscovery];
  114. [self _stopSAPDiscovery];
  115. }
  116. }
  117. - (void)_startUPNPDiscovery
  118. {
  119. if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
  120. return;
  121. UPnPManager *managerInstance = [UPnPManager GetInstance];
  122. _UPNPdevices = [[managerInstance DB] rootDevices];
  123. if (_UPNPdevices.count > 0)
  124. [self UPnPDBUpdated:nil];
  125. [[managerInstance DB] addObserver:self];
  126. //Optional; set User Agent
  127. [[managerInstance SSDP] setUserAgentProduct:[NSString stringWithFormat:@"VLCforiOS/%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]] andOS:[NSString stringWithFormat:@"iOS/%@", [[UIDevice currentDevice] systemVersion]]];
  128. //Search for UPnP Devices
  129. [[managerInstance SSDP] startSSDP];
  130. [[managerInstance SSDP] notifySSDPAlive];
  131. _searchTimer = [NSTimer timerWithTimeInterval:10.0 target:self selector:@selector(_performSSDPSearch) userInfo:nil repeats:YES];
  132. [_searchTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
  133. [[NSRunLoop mainRunLoop] addTimer:_searchTimer forMode:NSRunLoopCommonModes];
  134. _udnpDiscoveryRunning = YES;
  135. }
  136. - (void)_performSSDPSearch
  137. {
  138. UPnPManager *managerInstance = [UPnPManager GetInstance];
  139. [[managerInstance SSDP] searchSSDP];
  140. [[managerInstance SSDP] searchForMediaServer];
  141. [[managerInstance SSDP] SSDPDBUpdate];
  142. }
  143. - (void)_stopUPNPDiscovery
  144. {
  145. if (_udnpDiscoveryRunning) {
  146. UPnPManager *managerInstance = [UPnPManager GetInstance];
  147. [[managerInstance SSDP] notifySSDPByeBye];
  148. [_searchTimer invalidate];
  149. _searchTimer = nil;
  150. [[managerInstance DB] removeObserver:self];
  151. [[managerInstance SSDP] stopSSDP];
  152. _udnpDiscoveryRunning = NO;
  153. }
  154. }
  155. - (IBAction)goBack:(id)sender
  156. {
  157. [self _stopUPNPDiscovery];
  158. [self _stopSAPDiscovery];
  159. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  160. }
  161. - (BOOL)shouldAutorotate
  162. {
  163. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  164. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  165. return NO;
  166. return YES;
  167. }
  168. #pragma mark - table view handling
  169. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  170. {
  171. return _sectionHeaderTexts.count;
  172. }
  173. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  174. {
  175. if (section == 0)
  176. return _filteredUPNPDevices.count;
  177. else if (section == 1)
  178. return _ftpServices.count;
  179. else if (section == 2)
  180. return _sapDiscoverer.discoveredMedia.count;
  181. return 0;
  182. }
  183. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCLocalNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  186. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  187. }
  188. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  189. {
  190. static NSString *CellIdentifier = @"LocalNetworkCell";
  191. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  192. if (cell == nil)
  193. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  194. NSUInteger row = indexPath.row;
  195. NSUInteger section = indexPath.section;
  196. [cell setIsDirectory:YES];
  197. [cell setIcon:nil];
  198. if (section == 0) {
  199. UIImage *icon;
  200. if (_filteredUPNPDevices.count > row) {
  201. BasicUPnPDevice *device = _filteredUPNPDevices[row];
  202. [cell setTitle:[device friendlyName]];
  203. icon = [device smallIcon];
  204. }
  205. [cell setIcon:icon != nil ? icon : [UIImage imageNamed:@"serverIcon"]];
  206. } else if (section == 1) {
  207. if (row == 0)
  208. [cell setTitle:_ftpServices[row]];
  209. else {
  210. [cell setTitle:[_ftpServices[row] name]];
  211. [cell setIcon:[UIImage imageNamed:@"serverIcon"]];
  212. }
  213. } else if (section == 2)
  214. [cell setTitle:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] metadataForKey: VLCMetaInformationTitle]];
  215. return cell;
  216. }
  217. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  218. {
  219. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  220. NSUInteger row = indexPath.row;
  221. NSUInteger section = indexPath.section;
  222. if (section == 0) {
  223. if (_filteredUPNPDevices.count < row || _filteredUPNPDevices.count == 0)
  224. return;
  225. [_activityIndicator startAnimating];
  226. BasicUPnPDevice *device = _filteredUPNPDevices[row];
  227. if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
  228. MediaServer1Device *server = (MediaServer1Device*)device;
  229. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithUPNPDevice:server header:[device friendlyName] andRootID:@"0"];
  230. [self.navigationController pushViewController:targetViewController animated:YES];
  231. }
  232. } else if (section == 1) {
  233. UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_loginViewController];
  234. [navCon loadTheme];
  235. navCon.navigationBarHidden = NO;
  236. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  237. navCon.modalPresentationStyle = UIModalPresentationFormSheet;
  238. [self presentViewController:navCon animated:YES completion:nil];
  239. if (_loginViewController.navigationItem.leftBarButtonItem == nil) {
  240. UIBarButtonItem *doneButton = [UIBarButtonItem themedDoneButtonWithTarget:_loginViewController andSelector:@selector(dismissWithAnimation:)];
  241. _loginViewController.navigationItem.leftBarButtonItem = doneButton;
  242. }
  243. } else
  244. [self.navigationController pushViewController:_loginViewController animated:YES];
  245. if (row != 0 && [_ftpServices[row] hostName].length > 0) // FTP Connect To Server Special Item and hostname is long enough
  246. _loginViewController.hostname = [_ftpServices[row] hostName];
  247. else
  248. _loginViewController.hostname = @"";
  249. } else if (section == 2) {
  250. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  251. [appDelegate openMovieFromURL:[[_sapDiscoverer.discoveredMedia mediaAtIndex:row] url]];
  252. }
  253. }
  254. #pragma mark - Refresh
  255. -(void)handleRefresh
  256. {
  257. UPnPManager *managerInstance = [UPnPManager GetInstance];
  258. [[managerInstance DB] removeObserver:self];
  259. [[managerInstance SSDP] stopSSDP];
  260. //set the title while refreshing
  261. _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"LOCAL_SERVER_REFRESH",nil)];
  262. //set the date and time of refreshing
  263. NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
  264. [formattedDate setDateFormat:@"MMM d, h:mm a"];
  265. NSString *lastupdated = [NSString stringWithFormat:NSLocalizedString(@"LOCAL_SERVER_LAST_UPDATE",nil),[formattedDate stringFromDate:[NSDate date]]];
  266. _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated];
  267. //end the refreshing
  268. [_refreshControl endRefreshing];
  269. [self.tableView reloadData];
  270. [self performSelectorInBackground:@selector(_startUPNPDiscovery) withObject:nil];
  271. [self performSelectorInBackground:@selector(_startSAPDiscovery) withObject:nil];
  272. }
  273. #pragma mark - login panel protocol
  274. - (void)loginToURL:(NSURL *)url confirmedWithUsername:(NSString *)username andPassword:(NSString *)password
  275. {
  276. if ([url.scheme isEqualToString:@"ftp"]) {
  277. if (url.host.length > 0) {
  278. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithFTPServer:url.host userName:username andPassword:password atPath:@"/"];
  279. [self.navigationController pushViewController:targetViewController animated:YES];
  280. }
  281. } else
  282. APLog(@"Unsupported URL Scheme requested %@", url.scheme);
  283. }
  284. #pragma mark - custom table view appearance
  285. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  286. {
  287. return 21.f;
  288. }
  289. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  290. {
  291. NSObject *headerText = NSLocalizedString(_sectionHeaderTexts[section], @"");
  292. UIView *headerView = nil;
  293. if (headerText != [NSNull null]) {
  294. headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 21.0f)];
  295. if (!SYSTEM_RUNS_IOS7_OR_LATER) {
  296. CAGradientLayer *gradient = [CAGradientLayer layer];
  297. gradient.frame = headerView.bounds;
  298. gradient.colors = @[
  299. (id)[UIColor colorWithRed:(66.0f/255.0f) green:(66.0f/255.0f) blue:(66.0f/255.0f) alpha:1.0f].CGColor,
  300. (id)[UIColor colorWithRed:(56.0f/255.0f) green:(56.0f/255.0f) blue:(56.0f/255.0f) alpha:1.0f].CGColor,
  301. ];
  302. [headerView.layer insertSublayer:gradient atIndex:0];
  303. } else
  304. headerView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  305. UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 12.0f, 5.0f)];
  306. textLabel.text = (NSString *) headerText;
  307. textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:([UIFont systemFontSize] * 0.8f)];
  308. textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
  309. textLabel.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.25f];
  310. textLabel.textColor = [UIColor colorWithRed:(118.0f/255.0f) green:(118.0f/255.0f) blue:(118.0f/255.0f) alpha:1.0f];
  311. textLabel.backgroundColor = [UIColor clearColor];
  312. [headerView addSubview:textLabel];
  313. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  314. topLine.backgroundColor = [UIColor colorWithRed:(95.0f/255.0f) green:(95.0f/255.0f) blue:(95.0f/255.0f) alpha:1.0f];
  315. [headerView addSubview:topLine];
  316. UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 21.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  317. bottomLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f];
  318. [headerView addSubview:bottomLine];
  319. }
  320. return headerView;
  321. }
  322. #pragma mark - bonjour discovery
  323. - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
  324. {
  325. APLog(@"found bonjour service: %@ (%@)", aNetService.name, aNetService.type);
  326. [_rawNetServices addObject:aNetService];
  327. aNetService.delegate = self;
  328. [aNetService resolveWithTimeout:5.];
  329. }
  330. - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
  331. {
  332. APLog(@"bonjour service disappeared: %@ (%i)", aNetService.name, moreComing);
  333. if ([_rawNetServices containsObject:aNetService])
  334. [_rawNetServices removeObject:aNetService];
  335. if ([aNetService.type isEqualToString:@"_ftp._tcp."])
  336. [_ftpServices removeObject:aNetService];
  337. if (!moreComing)
  338. [self.tableView reloadData];
  339. }
  340. - (void)netServiceDidResolveAddress:(NSNetService *)aNetService
  341. {
  342. if ([aNetService.type isEqualToString:@"_ftp._tcp."]) {
  343. if (![_ftpServices containsObject:aNetService])
  344. [_ftpServices addObject:aNetService];
  345. }
  346. [_rawNetServices removeObject:aNetService];
  347. [self.tableView reloadData];
  348. }
  349. - (void)netService:(NSNetService *)aNetService didNotResolve:(NSDictionary *)errorDict
  350. {
  351. APLog(@"failed to resolve: %@", aNetService.name);
  352. [_rawNetServices removeObject:aNetService];
  353. }
  354. #pragma mark - UPNP details
  355. //protocol UPnPDBObserver
  356. - (void)UPnPDBWillUpdate:(UPnPDB*)sender
  357. {
  358. }
  359. - (void)UPnPDBUpdated:(UPnPDB*)sender
  360. {
  361. NSUInteger count = _UPNPdevices.count;
  362. BasicUPnPDevice *device;
  363. NSMutableArray *mutArray = [[NSMutableArray alloc] init];
  364. for (NSUInteger x = 0; x < count; x++) {
  365. device = _UPNPdevices[x];
  366. if ([[device urn] isEqualToString:@"urn:schemas-upnp-org:device:MediaServer:1"])
  367. [mutArray addObject:device];
  368. else
  369. APLog(@"found device '%@' with unsupported urn '%@'", [device friendlyName], [device urn]);
  370. }
  371. _filteredUPNPDevices = nil;
  372. _filteredUPNPDevices = [NSArray arrayWithArray:mutArray];
  373. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
  374. }
  375. #pragma mark SAP discovery
  376. - (void)_startSAPDiscovery
  377. {
  378. return;
  379. if (_reachability.currentReachabilityStatus != ReachableViaWiFi)
  380. return;
  381. _sapDiscoverer = [[VLCMediaDiscoverer alloc] initWithName:@"sap"];
  382. _sapDiscoverer.discoveredMedia.delegate = self;
  383. }
  384. - (void)_stopSAPDiscovery
  385. {
  386. return;
  387. _sapDiscoverer = nil;
  388. }
  389. - (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
  390. {
  391. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  392. }
  393. - (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(NSInteger)index
  394. {
  395. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  396. }
  397. @end