有人知道如何实现搜索模板,如苹果的tvOS人机界面指南,使用本机开发目标-C或Swift,没有TVML?

发布于 2016-06-30 06:51:14
所以,经过研究,我找到了一个解决办法:
目标- C
如果在应用程序中是tabBar,那么我从UITabBarController (例如APTabBarController )创建了一个子类。在APTabBarController中,方法上
- (void)viewDidLoad我接下来做的是:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SearchResultsViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"SearchResultsViewController"];
UISearchController *searchController = [[UISearchController alloc] initWithViewController:myViewController];
UISearchContainerViewController *containerVC = [[UISearchContainerViewController alloc] initWithSearchController: searchController];
containerVC.title = @"Search";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: containerVC];
NSMutableArray *newTab = [self.viewControllers mutableCopy];
[newTab addObject: navigationController];
[self setViewControllers: newTab];其中:
但是,我发现的问题是我找不到搜索的文本。为此,从UISearchController创建一个子类,并实现自定义
initWithViewController在我的例子中,看起来是这样的:
In .h
#import <UIKit/UIKit.h>
@interface SearchExercisesViewController : UISearchController
- (id) initWithViewController:(UIViewController *) viewController;
@endIn .m
#import "SearchExercisesViewController.h"
@interface SearchExercisesViewController () <UISearchBarDelegate>
@property (nonatomic, strong) UIViewController *viewController;
@end
@implementation SearchExercisesViewController
- (id) initWithViewController:(UIViewController *) viewController {
self = [super initWithSearchResultsController:viewController];
if (self) {
self.viewController = viewController;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.searchBar.delegate = self;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"%@",searchText);
}
@end利润,现在,取代
UISearchController *searchController = [[UISearchController alloc] initWithViewController:myViewController];使用
SearchExercisesViewController *searchController = [[SearchExercisesViewController alloc] initWithViewController:myViewController];全都做完了。现在只剩下这些,将数据发送到包含集合视图的viewController,并实现用于搜索的逻辑。对于发送的数据,您可以代表模式或NSNotification。您可以在这篇文章中找到如何实现这一点:
it possible to Pass Data with popViewControllerAnimated?
Swift
在斯威夫特也是一样,如何做到这一点,你可以从苹果的例子中找到以下链接:
发布于 2016-06-29 22:46:47
听起来你想看看UISearchController。
https://stackoverflow.com/questions/38095125
复制相似问题