2016-06-29 4 views
3

Apple tvOSヒューマンインタフェースガイドラインのように、Objective-CやSwiftのネイティブ開発をTVMLなしで使用すると、誰も検索テンプレートを実装する方法を知っていますか?検索テンプレートtvOS

答えて

3

ので、研究の1日後、私が見つかりました。解決策:

のObjective - アプリケーションがタブバーである場合で、私はUITabBarControllerなどからサブクラスを作成し

C APTabBarController。

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]; 

:APTabBarControllerでは、方法

- (void)viewDidLoad 

に私は次に何

  1. ストーリーボードを - 私のストーリーボード
  2. SearchResultsViewControllerは - collectionView
  3. が含まれているストーリーボードから私のコントローラであり、
  4. UISearchController - 許可するコントローラです。これらのいずれかが「NEWTAB」でtabBarController
  5. からのビューコントローラのようなものです - - 私は私が

が必要であることを新鮮に作成のViewControllerを追加しかし、私が見つけた問題があるあなたがUISearchContainerViewController

  • が必要なのですものを見つけるために私は検索されたテキストをキャッチできません。そのため、UISearchControllerからサブクラスを作成し、私の場合は、カスタム

    initWithViewController 
    

    を実装するには、これらのようになります.Mでの.h

    #import <UIKit/UIKit.h> 
    
    @interface SearchExercisesViewController : UISearchController 
    
    - (id) initWithViewController:(UIViewController *) viewController; 
    
    @end 
    

    #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 
    

    利益、そして今、すべて行わ

    SearchExercisesViewController *searchController = [[SearchExercisesViewController alloc] initWithViewController:myViewController]; 
    

    UISearchController *searchController = [[UISearchController alloc] initWithViewController:myViewController]; 
    

    を交換してください。今のところ残っているのは、コレクションビューを含むviewControllerにデータを送信し、検索ロジックを実装することだけです。送信されたデータの場合は、代行パターンまたはNSNotificationを使用できます。あなたはそのポストにそれを実装する方法を見つけることができます:

    it possible to Pass Data with popViewControllerAnimated?

    スウィフト

    を迅速にあなたがこれらのリンクから、アップルの例を見つけることができる、それを行う方法を、同じです。

    https://github.com/brunogb/TVExamples/tree/master/UIKitCatalogtvOSCreatingandCustomizingUIKitControls

  • 関連する問題