2012-08-01 50 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