2012-08-01 48 views
0

让我的代理“工作”有些困难。使用不同类别的代理

它在ClassA通过UINavigationController将ClassB推入堆栈时起作用,但当ClassB被不同的ClassC推送时,ClassB不会调用委托方法(在ClassA中)。

这种方法从内ClassA的工作原理:

- (void)openViewController:(NSString *)title:(int)dataType:(NSArray *)currentData {  
ClassB *nextController = [[ClassB alloc] initWithNibName:@"ClassBView" bundle:nil]; 
nextController.delegate = self; 
nextController.title = title; 
nextController.dataType = dataType; 
nextController.currentData = currentData; 
nextController.hidesBottomBarWhenPushed = YES; 
[self.navigationController pushViewController:nextController animated:YES];} 

我如何获得这个方法,从ClassC,正确的ClassA指定的委托ClassB的???

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
ClassB *nextController = [[ClassB alloc] initWithNibName:@"ClassBView" bundle:nil]; 
    nextController.delegate = ?????????? 
    nextController.title = [self.tableData objectAtIndex:indexPath.row]; 
    nextController.dataType = self.dataType; 
    nextController.currentData = [NSArray arrayWithArray:[self.dictionary objectForKey:[self.tableData objectAtIndex:indexPath.row]]]; 
    nextController.hidesBottomBarWhenPushed = YES; 
[self.navigationController pushViewController:nextController animated:YES];} 

感谢您的协助。干杯。

+0

你的问题令人困惑,因为你没有区分'class'和该类的一个实例。请检查这些概念并编辑您的问题以使其更清晰 – Olotiar 2012-08-01 15:30:21

+0

尝试更具体.... ClassB具有由ClassA或ClassC“推送”的特定视图。但是,每当ClassB发生变化时,我都希望它在ClassA中激发委托方法,而不管它是否是“推送”视图的ClassA或ClassC。当从ClassA“推”到ClassB时,很容易建立委托,但是如何将ClassA指定为ClassC的ClassB委托? ....清除泥浆,我确信.... – canuckpilot 2012-08-01 16:03:10

+0

在这种情况下,答案对我来说听起来很合理。但是,请检查类和类的实例之间的区别 – Olotiar 2012-08-01 16:09:42

回答

0

我觉得应该了解更多关于应用程序中的视图控制器层次结构的帮助,但听起来您需要在ClassC中添加对ClassA的引用,以便它可以传递给ClassB。所以(在ClassC中)nextController.delegate = self.ClassARef

+0

感谢您的帮助...仍在解决方案,并会发布它,如果我到达那里。 – canuckpilot 2012-08-03 02:25:23