Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Splitview + navigationbar tự code bằng tay lỗi không hiện ?

    mình thêm đoạn code này mà vẫn không đc
    [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];

    câu hỏi được rất nhiều người trên mạng hỏi như thế này:
    http://stackoverflow.com/questions/4987394/uisplitviewcontrollerdelegate-willhideviewcontroller-not-sending-a-uibarbut

    http://stackoverflow.com/questions/5618354/why-my-button-sometimes-disappears

    http://stackoverflow.com/questions/7365153/barbuttonitem-for-splitviewcontroller-not-shown-on-screen

    http://useyourloaf.squarespace.com/blog/2010/6/14/using-an-image-for-the-uisplitviewcontroller-popover-button.html

    mình sửa lại như thế này thì hiện lên nhưng không chọn được



    Mã:
    /*     File: FirstDetailViewController.m  */ #import "FirstDetailViewController.h"  @implementation FirstDetailViewController @synthesize toolbar; #pragma mark -#pragma mark View lifecycle - (void)viewDidUnload {    [super viewDidUnload];        self.toolbar = nil;}// Called when rotating to a portrait orientation.- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {    barButtonItem.title = @"Root List";    NSMutableArray *items = [[toolbar items] mutableCopy];    [items insertObject:barButtonItem atIndex:0];    [toolbar setItems:items animated:YES];    [items release];    popoverController = pc;}#pragma mark -#pragma mark Managing the popover - (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {        // Add the popover button to the toolbar.    NSMutableArray *itemsArray = [toolbar.items mutableCopy];    [itemsArray insertObject:barButtonItem atIndex:0];    [toolbar setItems:itemsArray animated:NO];    [itemsArray release];}  - (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {        // Remove the popover button from the toolbar.    NSMutableArray *itemsArray = [toolbar.items mutableCopy];    [itemsArray removeObject:barButtonItem];    [toolbar setItems:itemsArray animated:NO];    [itemsArray release];}  #pragma mark -#pragma mark Rotation support - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    return YES;}  #pragma mark -#pragma mark Memory management - (void)dealloc {    [toolbar release];    [super dealloc];}      @end



    Mã:
    /*     File: AppDelegate.m */ #import "AppDelegate.h"#import "RootViewController.h" @implementation AppDelegate @synthesize window, splitViewController;  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{        rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];    firstDetail1 = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];    splitViewController = [[UISplitViewController alloc] init];    splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, firstDetail1, nil];    splitViewController.delegate = firstDetail1;        [window addSubview:splitViewController.view];      [window makeKeyAndVisible];        return YES;}  - (void)dealloc {    [splitViewController release];    [window release];    [super dealloc];}  @end

  2. #2
    Ngày tham gia
    Sep 2015
    Đang ở
    Hà Nội
    Bài viết
    0
    Mã:
    Creating a Split View Controller Programmatically
    To create a split view controller programmatically, create a new instance of the UISplitViewController class and assign view controllers to its two properties. Because its contents are built on-the-fly from the view controllers you provide, you do not have to specify a nib file when creating a split view controller. Therefore, you can just use the init method to initialize it. Listing 5-2 shows an example of how to create and configure a split view interface at launch time. You would replace the first and second view controllers with the custom view controller objects that present your application’s content. The window variable is assumed to be an outlet that points to the window loaded from your application’s main nib file.
    
    Listing 5-2  Creating a split view controller programmatically
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       MyFirstViewController* firstVC = [[[MyFirstViewController alloc]
                         initWithNibName:@"FirstNib" bundle:nil] autorelease];
       MySecondViewController* secondVC = [[[MySecondViewController alloc]
                         initWithNibName:@"SecondNib" bundle:nil] autorelease];
     
       UISplitViewController* splitVC = [[UISplitViewController alloc] init];
       splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
     
       [window addSubview:splitVC.view];
       [window makeKeyAndVisible];
     
       return YES;
    }

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •