ios - 带有 NSNumber 的 CoreData

标签 ios xcode core-data nsnumber

我创建了一个包含多条记录的 sqlite CoreData 应用程序:

我的文件.h

@property (nonatomic, retain) NSNumber * game;
@property (nonatomic, retain) NSString * image;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * result;
@property (nonatomic, retain) NSNumber * totalWin;

我的文件.m

@dynamic game;
@dynamic image;
@dynamic name;
@dynamic resul;
@dynamic totalWin;

我在 UITableView 自定义中阅读了所有内容,但我会在第一页获得所有游戏的一般报告,例如:

如果我玩了 5 场比赛,我的 UITableView 中有 5 个单元格,如何才能在唯一的 NSNumber 中获得总金额,例如:

UILabel *myTotal;
myTotal = //here i want to get total game from all my cells

并且在 5 个单元格中有一个 NSNumber 游戏:

1St game = 5
2St game = 3
3St game = 4
4St game = 6
5St game = 1

如何在第一页显示这个数量的标签19

这是我加载到 TableView 的内容:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [archive count];
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    UILabel *gameName = (UILabel *)[cell viewWithTag:2];
    gameName.text = [archive[indexPath.row]name];

    int gameInt = [[archive [indexPath.row] game]intValue];
    UILabel *gameValue = (UILabel *)[cell viewWithTag:3];
    gameValue.text = [NSString stringWithFormat:@"%d",gameInt];

    return cell;
}

最佳答案

用 Larme 代码解决了,谢谢

Try [archive valueForKeyPath:@"@sum.game"]; (or replace game, by resul, totalWin or whatever you want).

关于ios - 带有 NSNumber 的 CoreData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25014577/

相关文章:

ios - 将 PNG 保存到磁盘,但将文件路径保存到核心数据

ios - 类型为 'CFTypeRef _Nullable'(又名 'const void *')的集合元素不是 Objective-C 对象

ios - AutoLayout 多行 UILabel 切断了一些文本

ios - 在所有 View Controller 中隐藏状态栏 - IOS

swift - 如何以编程方式在 UIScrollView 中设置 StickyHeader

objective-c - 尝试通过核心数据保存文档窗口尺寸

ios - Mapkit 标注附件按钮激活

ios - 无法将多个 UIButton 连接到我的 IBAction

ios - 'UIImageView' 没有可见的@interface 声明选择器 'setImageWithURL'

iphone - 核心数据 : crash when merge change, 由于 'objc_msgSend'