我對這個問題a custom delegate method inside didSelectRowAtIndexPath有點類似的問題。設置委託對象中的委託方法沒有響應
但是,在我的情況下,在獲得委託對象之前,它是一個名爲BarCodeViewController的UIViewController,我應該首先通過2個視圖控制器從初始視圖控制器CardViewController這是一個表視圖控制器。我通過這個設置爲我的自定義委託的委託對象:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CardDetailsViewController *details = [self.storyboard instantiateViewControllerWithIdentifier:@"cardDetails"];
Card *selectedCard = [self.myWallet objectAtIndex:indexPath.row]; // I want this selected card to be accessible until the user clicks another card or during end of program.
[self.navigationController pushViewController:details animated:YES];
[self.delegate cardWalletViewController:self withCurrentCard:selectedCard];
[self setDelegate:self.barCodeVC]; // barCodeVC is declared in CardWalletViewController.h as @property (nonatomic, strong) BarCodeViewController *barCodeVC;
if (self.delegate) {
NSLog(@"delegate is not nil");
}
}
,這是我如何實例化,我設置爲委託對象
- (void)viewDidLoad
{
[self setBarCodeVC:[self.storyboard instantiateViewControllerWithIdentifier:@"myBarcodeVC"]];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
而在我的委託對象視圖控制器,這是BarCodeViewController我實現委託方法
#import "CardWalletViewController.h"
@interface BarCodeViewController() <CardWalletDelegate>
@end
@implementation
- (void)cardWalletViewController:(CardWalletViewController *)sender withCurrentCard:(Card *)currentCard
{
Card *myCurrentCard = currentCard;
NSLog(@"This is my current card: %@", myCurrentCard);
}
@end
我想我能夠把我的委託對象,但後來沒有被實施的委託方法我沒有看到在控制檯NSLog(@「這是我目前的......」);當我到達BarCodeViewController時。
請諮詢。
我希望發生的是將selectedCard傳遞給barCodeViewController,它是barCodeVC(編輯我的文章)。關於你的見解,我沒有完全明白你的意思。 – Grauzten 2012-04-26 03:35:02
編輯:在[self setDelegate:self.barCodeVC]旁邊添加了一條評論; – Grauzten 2012-04-26 03:42:22
明白了。 Ahm我放置了[self setDelegate:selfBarCodeVC];到viewDidLoad方法,以便我可以立即設置我的委託。但是,一旦我到達BarCodeViewController,委託方法仍然沒有響應。請注意,在我可以訪問BarCodeViewController之前,在單擊CardWalletViewController中的表格單元格後,我會傳遞另一個表視圖(名爲CardDetailsViewController)。然後,一旦我點擊另一個表格單元格(引用CardDetailsViewController),就會顯示一個新的視圖控制器,它是PerksDetailsViewController。 (接下來...) – Grauzten 2012-04-26 04:06:57