2012-05-17 68 views
0

我工作在继承UIViewControllers但我与它面临的问题。下面是我使用的ViewController列表及其流程。继承在UIViewController中

头文件

MainViewController : UIViewController { 

} 

CustomerTicketViewController : UIViewController { 

} 
@property (nonatomic, retain) NSArray *listTickets; 

CustomerEditTicketViewController : CustomerTicketViewController { 

} 

实施文件

@implementation MainViewController 

- (void)loadCustomer { 
     CustomerTicketViewController *customerTicketViewController = [[CustomerTicketViewController alloc] initWithNibName:@"CustomerTicketViewController" bundle:nil]; 
     [customerTicketViewController setListTickets:myTickets]; 
     [self presentModalViewController:customerTicketViewController animated:YES]; 
     [customerTicketViewController release]; 
} 

@end 

@implementation CustomerTicketViewController 

    - (void)editCustomer { 
     CustomerEditTicketViewController *customerEditTicketViewController = [[CustomerEditTicketViewController alloc] initWithNibName:@"CustomerEditTicketViewController" bundle:nil]; 
     NSLog(@"ParentView.listTickets: %@", listTickets); 
     [self presentModalViewController:customerEditTicketViewController animated:NO]; 
     [customerEditTicketViewController release]; 
    } 

    @end 

@implementation CustomerEditTicketViewController 

- (void)viewDidLoad { 
    NSLog(@"listTickets: %@", listTickets); 
    NSLog(@"super.listTickets: %@", super.listTickets); 
    NSLog(@"self->listTickets: %@", self->listTickets); 
    NSLog(@"self.listTickets: %@", self.listTickets); 
} 

@end 

在子类打印空,但按我的理解,他们应该打印相同的值作为ParentView日志。 请指导我,如果我错了一些地方。

ParentView.listTickets: (
    "<CustomerTicket: 0x4c75d90>", 
    "<CustomerTicket: 0x4c76310>" 
) 

listTickets: (null) 
super.listTickets: (null) 
self->listTickets: (null) 
self.listTickets: (null) 

回答

3

您的编辑视图控制器是一个单独的对象。所有它从超类继承的是,它有一个叫做listTickets ,,不是属性的值一个数组属性的事实。这是面向对象编程中的一个(?)基本点。

你创建的第一个时,就像你做创建视图控制器后设定值:

CustomerEditTicketViewController *customerEditTicketViewController = [[CustomerEditTicketViewController alloc] initWithNibName:@"CustomerEditTicketViewController" bundle:nil]; 

customerEditTicketViewController.listTickets = self.listTickets; 
0

您的视图控制器的editCustomer方法不会使分配到子控制器的性能。