block使用总结2

1.场景:点击自定义tableviewCell中的一个imageView(属于控制器A)--跳转到控制器B.
2.分析:在自定义的tableviewCell中,push到控制器B,是不可能实现的,因为拿不到navigationController,点击imageView时需要让控制器A帮忙实现push的操作.
3.解决:在tableviewCell 中定义block(),在点击imageView方法中,调用block. 在控制器A中实现block.
4.结论:大哥让小弟办事. 大哥去定义和调用,小弟去实现.
代码如下:

  #import "VWHomeViewController.m"   --控制器A:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VWDataPickerCell *mcell = [tableView dequeueReusableCellWithIdentifier:datePickerID forIndexPath:indexPath];
    
    mcell.pushToSearchVC = ^{
        
        VWSearchTableViewController *searchVC = [[VWSearchTableViewController alloc] init];
        searchVC.allFeatures = self.claimsArray;
        searchVC.allFeaturesNames = self.claimsTemplateName;
        [self.navigationController pushViewController:searchVC animated:YES];
      
    };
  return mcell;
  }

#import "VWDataPickerCell.h" 
 typedef void (^VWPushToSearchVC)();
 @property (nonatomic, copy) VWPushToSearchVC pushToSearchVC;

#import "VWDataPickerCell.m"
// imageView的点击方法
-(void)searchVC{
     //    如果实现了就调用block方法
    if (self.pushToSearchVC) {
        self.pushToSearchVC();
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容