小编Ken*_*ili的帖子

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

我正在向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);
}
Run Code Online (Sandbox Code Playgroud)

这是警告信息:

警告:"不兼容的指针类型使用UIView*类型的表达式初始化UITableViewCell*"

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

objective-c uitableview ios

5
推荐指数
1
解决办法
797
查看次数

从另一个视图控制器通知视图控制器

我在ViewController中有一个Segment Control和一个Container.在容器中是一个PageViewController.如果单击"段控制"中的某个项目,则会更改"user"表的"active"值.(sqlite)表"user":

username text, active bool
user1, false
user2,true
Run Code Online (Sandbox Code Playgroud)

因此,如果单击"段控制"中的user1,表格将更改为

username text, active bool
    user1, true
    user2,false
Run Code Online (Sandbox Code Playgroud)

是否有一种方法可以使PageViewController中的所有ViewControllers识别数据库中的更改并使用新用户重新加载其数据.如果这不可能,那么最好的方法是什么?

亲切的问候

ios swift

2
推荐指数
1
解决办法
744
查看次数

标签 统计

ios ×2

objective-c ×1

swift ×1

uitableview ×1