ios – 如何通过单击单元格的子视图获取UITableViewCell的indexPath – 获取不兼容的指针类型警告

ios – 如何通过单击单元格的子视图获取UITableViewCell的indexPath – 获取不兼容的指针类型警告,第1张

概述我正在向contentView添加一个开关,而contentView属于该单元格. 我正在尝试获取触发开关的单元格的行号. 这是代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = 我正在向contentVIEw添加一个开关,而contentVIEw属于该单元格.
我正在尝试获取触发开关的单元格的行号.

这是代码:

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"MainCell"];    if (cell == nil) {        cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:@"MainCell"];    }    UISwitch *theSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];    [cell addSubvIEw:theSwitch];    cell.accessoryVIEw = theSwitch;    [theSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];    return cell;}- (voID) switchChanged:(UISwitch *)sender {    UItableVIEwCell *theParentCell = [[sender supervIEw] supervIEw]; // Throwing Warning here     NSIndexPath *indexPathOfSwitch = [maintableVIEw indexPathForCell:theParentCell];    NSLog(@"the index path of the switch: %ld",(long)indexPathOfSwitch.row);}

这是警告信息:

Warning: “Incompatible pointer types initializing UItableVIEwCell *
with an Expression of type UIVIEw *”

发件人应该是什么而不是supervIEw?

解决方法 如果我理解正确,您正在尝试获取切换父单元格索引.

-(NSIndexPath *)indexPathWithSubvIEw:(UIVIEw *)subvIEw {    while (![subvIEw isKindOfClass:[UItableVIEwCell self]] && subvIEw) {        subvIEw = subvIEw.supervIEw;    }    return [self.mytable indexPathForCell:(UItableVIEwCell *)subvIEw];}- (voID) switchChanged:(UISwitch *)sender {    NSIndexPath *apath = [self indexPathWithSubvIEw:(UISwitch *)sender];}
总结

以上是内存溢出为你收集整理的ios – 如何通过单击单元格的子视图获取UITableViewCell的indexPath – 获取不兼容指针类型警告全部内容,希望文章能够帮你解决ios – 如何通过单击单元格的子视图获取UITableViewCell的indexPath – 获取不兼容的指针类型警告所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1069603.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存