代理

1。

   if ([_delegate respondsToSelector:@selector(subViewSelectRow:)]) {//这句话为了保证程序的健壮性,而要写的,以后要记住

        [_delegate subViewSelectRow:[_dataArr objectAtIndex:indexPath.row]];

    }

//还有要注意的是,一个类遵守了另一个类中的方法,并不一定意味着一定要该方法中完成.delegate=self;

也可以在别的类中声明;如下:

#import "AppDelegate.h"

#import "RootViewController.h"

#import "SubTableViewController.h"

@implementation AppDelegate

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    

    //iPad,坐标都统一768*1024

    

    //主要介绍两个独有的类,与iPhone的不同

//    UISplitViewController  //分栏控制器,只能管理两个视图控制器

//    UIPopoverController

    RootViewController *rvc=[[RootViewController alloc]init];

    UINavigationController *rnc1=[[UINavigationController alloc]initWithRootViewController:rvc];

    

    SubTableViewController *svc=[[SubTableViewController alloc]init];

//这里的RootViewController要遵守SubTableViewController 中的协议

    svc.delegate=rvc;

    UINavigationController  *snc2=[[UINavigationController alloc]initWithRootViewController:svc];

    //默认会隐藏数组中的第0个vc的view

    NSArray *arr=[NSArray arrayWithObjects:snc2,rnc1, nil];

    

    UISplitViewController *split=[[UISplitViewController alloc]init];

    split.delegate=rvc;

    split.viewControllers=arr;

    self.window.rootViewController=split;

    

    

    

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

posted @ 2015-02-06 16:02  一个酷德  阅读(132)  评论(0编辑  收藏  举报