码迷,mamicode.com
首页 > 其他好文 > 详细

Hdfs的ACL测试

时间:2014-04-27 21:18:00      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:使用   io   for   re   c   代码   

我们一般切换UIViewController的时候用的是如下代码

#import "UIViewControllerDemo.h"


UIViewControllerDemo *vc = [UIViewControllerDemo alloc] initWithNibName:nil bundle:nil] autorelease];
[self.navigationController pushViewController:vc animated:YES];

当我们需要切换的UIViewController多的时候呢,代码难免写成:

#import "UIViewControllerDemo1.h"
 #import "UIViewControllerDemo2.h"
 #import "UIViewControllerDemo3.h"
 #import "UIViewControllerDemo4.h"

 UIViewControllerDemo1 *vc1
 UIViewControllerDemo2 *vc2
 UIViewControllerDemo3 *vc3
 UIViewControllerDemo4 *vc4

以后维护的时候很是麻烦
下面我们将对UIViewController切换的方法进行改造

-(void) pushVC:(NSString *)vcName{
    Class class = NSClassFromString(vcName);
    NSAssert(class != nil, @"Class 必须存在");
    UIViewController *vc = [[[NSClassFromString(vcName) alloc] init] autorelease];

    [self.navigationController pushViewController:vc animated:YES];
}

这里可以加入一个协议,使用我们指定的方法来初始化,这样可以在初始话的同时带入参数

@protocol XYSwitchControllerProtocol <NSObject>
-(id) initWithObject:(id)object;
@end


-(void) pushVC:(NSString *)vcName object:(id)object{
    Class class = NSClassFromString(vcName);
    NSAssert(class != nil, @"Class 必须存在");
    UIViewController *vc = nil;

    if ([class conformsToProtocol:@protocol(XYSwitchControllerProtocol)]) {
        vc = [[[NSClassFromString(vcName) alloc] initWithObject:object] autorelease];
    }else {
        vc = [[[NSClassFromString(vcName) alloc] init] autorelease];
        vc.parameters = object;
    }

    [self.navigationController pushViewController:vc animated:YES];
}

模态的方法则多个考虑个UINavigationController

-(void) modalVC:(NSString *)vcName withNavigationVC:(NSString *)nvcName object:(id)object succeed:(UIViewController_block_void)block{
    Class class = NSClassFromString(vcName);
    NSAssert(class != nil, @"Class 必须存在");

    UIViewController *vc = nil;

    if ([class conformsToProtocol:@protocol(XYSwitchControllerProtocol)]) {
        vc = [[[NSClassFromString(vcName) alloc] initWithObject:object] autorelease];
    }else {
        vc = [[[NSClassFromString(vcName) alloc] init] autorelease];
        vc.parameters = object;
    }

    UINavigationController *nvc = nil;
    if (nvcName) {
        nvc = [[[NSClassFromString(vcName) alloc] initWithRootViewController:vc] autorelease];
        [self presentViewController:nvc animated:YES completion:block];

        return;
    }

    [self presentViewController:vc animated:YES completion:block];
}

Hdfs的ACL测试,码迷,mamicode.com

Hdfs的ACL测试

标签:使用   io   for   re   c   代码   

原文地址:http://blog.csdn.net/j2eelamp/article/details/24594159

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!