gpt4 book ai didi

iphone - cellForRowAtIndexPath 处的小计

转载 作者:行者123 更新时间:2023-11-29 04:49:46 25 4
gpt4 key购买 nike

我有两个实体:日记帐和帐户。这种关系是一对多的:Journal 只有一个 Account。账户有很多日记账。我想根据每个帐户的日记显示总计,但我不知道如何操作。目前我为每个帐户获得的总额是相同的:

在我的 UITableView (Accounts.m) 中,我有:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
static NSString *CellIdentifier = @"Cell";
XbAccountsN *cell = (XbAccountsN *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"XbAccountsN" owner:self options:nil];
cell = xbAccountsN;
self.xbAccountsN = nil;
GMAccount *awCuentasy = (GMAccount *)[self.fetchedResultsController objectAtIndexPath:indexPath];
cell.cnAlias.text = awCuentasy.cnAlias;
NSDecimalNumber *saldoAc = [NSDecimalNumber decimalNumberWithString:@"0.0"];
for (NSManagedObject *object in [self.fetchedResultsController fetchedObjects]) {
NSLog( @"Looping");
NSDecimalNumber *objectExpenseNumber = [object valueForKeyPath:@"journals.@sum.pzAmount01"];
balanceC = [balanceC decimalNumberByAdding:objectExpenseNumber];
}
NSNumberFormatter* bf = [[NSNumberFormatter alloc] init];
[bf setNumberStyle:NSNumberFormatterCurrencyStyle];
cell.cnSaldo.text = [bf stringFromNumber: balanceC];
[bf release];

即使我只有两个帐户以及与每个帐户相关的多个期刊,我也会为每个帐户获得相同的金额。如何为每个帐户提供正确的余额?请你帮助我好吗?。提前致谢。

最佳答案

好的。看来您正在 if (cell == nil) block 中设置单元格标签。这是不正确的。请注意,在 tableView 中,单元格被回收,并且当创建足够数量的单元格时,不再调用该 block ,因为旧单元格在回收队列中可用。好的。下面是正确的方法。 (检查语法,我在这里写的)。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
static NSString *CellIdentifier = @"Cell";

XbAccountsN *cell = (XbAccountsN *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

if (cell == nil) {
// Init new cell from nib archive (assuming the cell is the top most object in your xib)
cell = (UITableviewCell*)[[[NSBundle mainBundle] loadNibNamed:@"XbAccountsN" owner: nil options:nil] objectAtIndex: 0];
}

// Calculate your sum for the given awCuentasy
GMAccount *awCuentasy = (GMAccount *)[self.fetchedResultsController objectAtIndexPath:indexPath];

cell.cnAlias.text= awCuentasy.cnAlias;
NSDecimalNumber *saldoAc = [NSDecimalNumber decimalNumberWithString:@"0.0"];
for (NSManagedObject *object in [self.fetchedResultsController fetchedObjects]) {
NSLog( @"Looping");
NSDecimalNumber *objectExpenseNumber = [object valueForKeyPath:@"journals.@sum.pzAmount01"];
balanceC = [balanceC decimalNumberByAdding:objectExpenseNumber];}
NSNumberFormatter* bf = [[NSNumberFormatter alloc] init];
[bf setNumberStyle:NSNumberFormatterCurrencyStyle];
cell.cnSaldo.text= [bf stringFromNumber: balanceC];
[bf release];
}

return cell;

}

关于iphone - cellForRowAtIndexPath 处的小计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9038061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com