从tableview单元格中获取数据?

时间:2011-02-17 20:59:11

标签: cocoa-touch core-data

上帝晚上:-D

我有一个tableview,(使用核心数据)我用“Todo”发布单元格,如:“5英里运行”,我将详细文本设置为@“点值@”,X是x是一个数字集通过滑块,同时你为Todo设置名称。

我已在单元格中放入一个按钮,并将其称为add,我希望能够将详细文本中的该数字添加到我的核心数据模型中的“totalPoints”属性中。

我可以为实体制作fetchRequest,但是如何确保我得到那个数字,以及当“pointValue”存储在NSNumber对象中时如何使用简单数学。

更新:

修正了它:-D

如果你向你的单元格添加一个按钮,你可以像这样获得indexPath:

- (IBAction)buttonTapped:(id)sender {


if (![sender isKindOfClass: [UIButton class]]) return;  

UITableViewCell *cell = (UITableViewCell *)[sender superview];
if (![cell isKindOfClass: [UITableViewCell class]]) return;  

NSIndexPath *indexPath = [self.tableView indexPathForCell: cell];

// do something with indexPath.row and/or indexPath.section.

这修复了我的应用,现在正在进行beta测试:-P

感谢您的帮助

Skov的

1 个答案:

答案 0 :(得分:0)

在您的示例代码中,有几个问题。首先,当你得到值a,b和e时,你可以这样做:

NSNumber *a = toDo.pointsValue;

(假设toDo.pointsValue是NSNumber)。

其次,在if语句中,您要比较指针的值,而不是指针指向的对象中的值。

此代码应该具有您想要的结果(我假设您以某种方式初始化为Do):

ToDo *toDo;
CGFloat x = [toDo.pointsValue floatValue] + [toDo.totalPoint floatValue];
//Note: it is better to use CGFloat rather than plain float
CGFloat y = [toDo.goodiesPoints floatValue];
if (x >= y)
{
    [self performSelector:@selector(winView) 
               withObject:nil 
               afterDelay:0.5];
}

当你说“我如何确保我得到那个号码”时,我不确定你的意思。什么号码是“那个号码”?

相关问题