[英]CoreData with NSNumber
我创建了一个带多个记录的sqlite
CoreData应用程序:
myFile.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;
myFile.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
如何在firsrt页面上显示此数量的标签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代码解决了谢谢
尝试
[archive valueForKeyPath:@"@sum.game"];
(或将游戏替换为resul,totalWin或您想要的任何东西)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.