UITableViewCell - 接收 Stepper 实例值 [英] UITableViewCell - Receive Stepper instance value

查看:22
本文介绍了UITableViewCell - 接收 Stepper 实例值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个 UITableViewController,它填充了一个具有健身属性的自定义单元格 - 简介要求用户在超过/错过他们的目标时能够输入实际"值 - 我为此添加了一个步进器- 步进器连接到自定义单元格 .h 文件 - 后者又连接到 uitableviews .m 文件.

I have setup a a UITableViewController which populates a custom cell with fitness attributes - the brief requires the user to be able to enter a 'actual' value if they have exceeded / missed their taget - I've added a stepper for this purpose - the stepper is connected to the custom cells .h file - which in turn is connected to the uitableviews .m file.

我正在努力理解如何将更改后的值传递回 uitableviewcontroller 以及我如何知道哪个实例传递了该值!?

I'm struggling to understand how could I pass the altered value back to the uitableviewcontroller and how would I know which instance has passed the value!?

推荐答案

这些东西...

    - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
        MyCustomCell* cell = [tableView dequeueReusableCellForIdentifier:MyCustomCellIdentifier];
        // If newly created cell we need to add a target
        if (![[cell.stepperControl allTargets] containsObject:self])
        {
            [cell.stepperControl addTarget:self action:@selector(stepped:) forControlEvents:UIControlEventValueChanged];
        }

        cell.stepperControl.tag = indexPath.row + indexPath.section * 10000;

        // Rest of configuration...

        return cell;
    }

    - (void)stepped:(UIStepper*)stepper
    {
        int row = stepper.tag % 10000;
        int section = stepper.tag / 10000;

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

        // Now you know which row was changed so get the cell
        MyCustomCell *cell = (MyCustomCell*)[self.tableView cellForRowAtIndexPath:indexPath];

        // Read required data from the cell through custom properties...

    }

这篇关于UITableViewCell - 接收 Stepper 实例值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆