簡體   English   中英

具有NSNumber的CoreData

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM