我创建了一个包含多条记录的 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/