tabblecell上子view 的点击跳转以及获取cell 的属性

1.最简单的,给cell赋值cell.objc = self;

[self.objc.navigationControllerpushViewController:knowledgeVCanimated:YES];

2.通过代理方法

cell.h

@protocolMessageCellDelegate

- (void)shareBtnAction:(UIButton*)sender;

@end

[self.pushBackVaddSingleTap:self.delegate action:@selector(shareBtnAction:)];

3.通过cell的block

//TableViewCell的.h中:

#import

typedef void(^BlockButton)(NSString *str);

@interface TableViewCell : UITableViewCell

//block属性

@property (nonatomic, copy) BlockButton button;

//自定义block方法

- (void)handlerButtonAction:(BlockButton)block;

@end

//TableViewCell的.m中:

//与cell上的button关联的点击事件

- (IBAction)buttonOnCellAction:(UIButton *)sender {

if (self.button) {

self.button(self.buttonOnCell.titleLabel.text);

}

}

//block的实现部分

- (void)handlerButtonAction:(BlockButton)block

{

self.button = block;

}

//TableViewController的.m文件中: 其中self.arr 是一个定义为属性的可变数组 里边随意存储一些数据 用来在button上显示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell" forIndexPath:indexPath];

cell.title.text = [NSString stringWithFormat:@"%d" ,indexPath.row];

[cell.buttonOnCell setTitle:[self.arr objectAtIndex:indexPath.row] forState:UIControlStateNormal];

[cell handlerButtonAction:^(NSString *str) {

NSLog(@"====%@", str);

}];

// Configure the cell...

return cell;

}

4.添加手势获取指定cell

MineTableViewCell*sectionCell = [myTableViewcellForRowAtIndexPath:indexPath];

//获取indexpath

- (NSIndexPath*)currentCellIndexPath:(UIView*)view

{

UIView* obj = view;

while (![objisKindOfClass:[MessageCellclass]]) {

obj = obj.superview;

}

MessageCell* cell = (MessageCell*)obj;

NSIndexPath* indexPath = [_tbViewindexPathForCell:cell];

return indexPath;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容