第一个界面KSCDiscoveryViewController 跳转到目标界面 KSCVendorViewController
《一》
KSCDiscoveryTableViewCell 头文件中:
@protocol KSCDiscoveryTableViewCellDelegate <NSObject>
- (void)tapToCell:(UITableViewCell *)cell;
@end
@property (weak, nonatomic) id<KSCDiscoveryTableViewCellDelegate> delegate;
KSCDiscoveryTableViewCell.m文件中
- (void)awakeFromNib {
self.imageCollectionView.backgroundColor = [UIColor clearColor];
self.avatarImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
//单击
singleTap.numberOfTapsRequired = 1;
//单手指
singleTap.numberOfTouchesRequired = 1;
//添加到avatarImageView
[self.avatarImageView addGestureRecognizer:singleTap];
}
- (void)singleTap:(UITapGestureRecognizer *)gesture
{
if ([self.delegate respondsToSelector:@selector(tapToCell:)]) {
[self.delegate tapToCell:self];
}
}
——————————————————————————————————————————————————
《二》
KSCDiscoveryViewController.m文件中
@interface KSCDiscoveryViewController () <KSCDiscoveryTableViewCellDelegate>
@property(nonatomic, retain) NSArray *dataSource;
tableView 的 cellForRowAtIndexPath 方法中 cell.delegate = self;//******
//点击头像
- (void)tapToCell:(UITableViewCell *)cell
{
NSIndexPath *index = [self.tableView indexPathForCell:cell];
NSDictionary *item = self.dataSource[index.row];
KSCVendorViewController *vendorVC = (KSCVendorViewController *)[UIViewController KS_loadInitialFromStoryboard:@"KSCVendor"];
vendorVC.memberID = item[@"member_id"];
[self.navigationController pushViewController:vendorVC animated:YES];
}