VLCLocalServerListViewController.m 19 KB

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