我对这个问题有一些类似的担忧,即 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(@"this is my current......"); 当我到达 BarCodeViewController 时。
请指教。