Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表视图上的EXC_错误访问(SIGSEGV):cellForRowAtIndexPath_Ios_Uitableview_Crash - Fatal编程技术网

Ios 表视图上的EXC_错误访问(SIGSEGV):cellForRowAtIndexPath

Ios 表视图上的EXC_错误访问(SIGSEGV):cellForRowAtIndexPath,ios,uitableview,crash,Ios,Uitableview,Crash,我已经启用了NSZombieEnabled,当以下情况发生时,我似乎正在崩溃 通过选项卡栏转到“设置”视图控制器,然后从那里进入罪魁祸首视图控制器,然后单击另一个选项卡(之前不返回设置视图控制器),然后再次单击选项卡栏上的“设置” 这是tableView的代码:cellforrowatinexpath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)index

我已经启用了NSZombieEnabled,当以下情况发生时,我似乎正在崩溃

通过选项卡栏转到“设置”视图控制器,然后从那里进入罪魁祸首视图控制器,然后单击另一个选项卡(之前不返回设置视图控制器),然后再次单击选项卡栏上的“设置”

这是tableView的代码:cellforrowatinexpath

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

if(cell == nil)
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"temp"] autorelease];

cell.selectionStyle = UITableViewCellSelectionStyleGray;

if(indexPath.section == 1 && [PMSessionManager instance].paymentMethods.cards != nil)
{
    if([[PMSessionManager instance].paymentMethods.cards count] > indexPath.row)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        //Reverse the array if it's in the wrong order
        if([[[[PMSessionManager instance].paymentMethods.cards objectAtIndex:indexPath.row] cardStatus] isEqualToString:@"Secondary"] && indexPath.row == 0)
        {
            NSArray* reversedArray = [[[PMSessionManager instance].paymentMethods.cards reverseObjectEnumerator] allObjects];
            [PMSessionManager instance].paymentMethods.cards = reversedArray;
        }

        PMCardInfo *cardInfo = [[PMSessionManager instance].paymentMethods.cards objectAtIndex:indexPath.row];

        if([cardInfo.cardStatus isEqualToString:@"Primary"] && indexPath.row == 1)
            cardInfo = [[PMSessionManager instance].paymentMethods.cards objectAtIndex:(indexPath.row -1)];

        UILabel *cardLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     cell.indentationWidth,
                     0.075 * (tableView.rowHeight - 2 * 14),
                     200,
                     26)]
         autorelease];
        [cell.contentView addSubview:cardLabel];
        cardLabel.text = [NSString stringWithFormat:@"%@", [cardInfo.cardStatus capitalizedString]];
        cardLabel.backgroundColor = [UIColor clearColor];
        cardLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        cardLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];


        NSString *cardTypeString = [NSString stringWithFormat:@"%@", [cardInfo.cardType capitalizedString]];

        CGSize cardTypeStringSize = [cardTypeString sizeWithFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]];

        UILabel *cardTypeLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     cell.indentationWidth,
                     0.63 * (tableView.rowHeight - 2 * 14),
                     cardTypeStringSize.width,
                     24)]
         autorelease];
        [cell.contentView addSubview:cardTypeLabel];
        cardTypeLabel.text = [NSString stringWithFormat:@"%@", [cardInfo.cardType capitalizedString]];
        cardTypeLabel.backgroundColor = [UIColor clearColor];
        cardTypeLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        cardTypeLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];

        UILabel *digitsLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     cardTypeStringSize.width + 4 + cell.indentationWidth,
                     0.6 * (tableView.rowHeight - 2 * 14),
                     150,
                     26)]
         autorelease];
        [cell.contentView addSubview:digitsLabel];
        digitsLabel.text = [NSString stringWithFormat:@"ending with %@", cardInfo.last4Digits];
        digitsLabel.backgroundColor = [UIColor clearColor];
        digitsLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        digitsLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];

        //Let's make the expiration year just two digits
        if(cardInfo.expYear.length == 4)
            cardInfo.expYear = [cardInfo.expYear substringFromIndex:2];

        UILabel *expirationLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     cell.indentationWidth,
                     1.0 * (tableView.rowHeight - 2 * 14),
                     150,
                     26)]
         autorelease];
        [cell.contentView addSubview:expirationLabel];
        expirationLabel.text = [NSString stringWithFormat:@"Expires on %@/%@", cardInfo.expMonth, cardInfo.expYear];
        expirationLabel.backgroundColor = [UIColor clearColor];
        expirationLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        expirationLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
    }
    else 
    {
        UILabel *cardTypeLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     cell.indentationWidth,
                     0.25 * (tableView.rowHeight - 2 * 14),
                     275.0,
                     24)]
         autorelease];
        [cell.contentView addSubview:cardTypeLabel];
        if([[PMSessionManager instance].paymentMethods.cards count] == 2)
            cardTypeLabel.text = @"Swap Primary and Secondary Cards";
        else
            cardTypeLabel.text = @"Add Credit Card";
        cardTypeLabel.textAlignment = UITextAlignmentCenter;
        cardTypeLabel.backgroundColor = [UIColor clearColor];
        cardTypeLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        cardTypeLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    }
}
else if(indexPath.section == 0)
{
    if([PMSessionManager instance].paymentMethods.wallet != nil)
    {
        if(indexPath.row == 0)
        {
            NSString *balanceString = [Util numberToCurrencyString:[PMSessionManager instance].paymentMethods.wallet.balance];
            NSString *availableBalanceString = @"Available Balance";

            CGSize balanceStringSize = [balanceString sizeWithFont:[UIFont boldSystemFontOfSize:32.0]];
            CGSize availableBalanceStringSize = [availableBalanceString sizeWithFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]];

            CGFloat textWidth = balanceStringSize.width + 5.0 + availableBalanceStringSize.width;
            CGFloat margin = (275.0 - textWidth)/2;

            UILabel *balanceLabel =
            [[[UILabel alloc]
              initWithFrame:
              CGRectMake(
                         cell.indentationWidth + margin,
                         0.45 * (tableView.rowHeight - 2 * 14),
                         275.0,
                         32)]
             autorelease];
            [cell.contentView addSubview:balanceLabel];
            balanceLabel.text = balanceString;
            balanceLabel.textAlignment = UITextAlignmentLeft;
            balanceLabel.backgroundColor = [UIColor clearColor];
            balanceLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
            balanceLabel.font = [UIFont boldSystemFontOfSize:32.0];

            UILabel *walletBalanceLabel =
            [[[UILabel alloc]
              initWithFrame:
              CGRectMake(
                         balanceStringSize.width + 5 + cell.indentationWidth + margin,
                         0.72 * (tableView.rowHeight - 2 * 14),
                         275.0,
                         24)]
             autorelease];
            [cell.contentView addSubview:walletBalanceLabel];
            walletBalanceLabel.text = availableBalanceString;
            walletBalanceLabel.textAlignment = UITextAlignmentLeft;
            walletBalanceLabel.backgroundColor = [UIColor clearColor];
            walletBalanceLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
            walletBalanceLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];

            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if(indexPath.row == 1)
        {
            UILabel *walletSettingsLabel =
            [[[UILabel alloc]
              initWithFrame:
              CGRectMake(
                         cell.indentationWidth,
                         0.25 * (tableView.rowHeight - 2 * 14),
                         275.0,
                         24)]
             autorelease];
            [cell.contentView addSubview:walletSettingsLabel];
            walletSettingsLabel.text = @"Edit Wallet Settings";
            walletSettingsLabel.textAlignment = UITextAlignmentCenter;
            walletSettingsLabel.backgroundColor = [UIColor clearColor];
            walletSettingsLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
            walletSettingsLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
        }
    }
    else 
    {
        if(indexPath.row == 0)
        {
            UILabel *learnMoreLabel =
            [[[UILabel alloc]
              initWithFrame:
              CGRectMake(
                         cell.indentationWidth,
                         0.25 * (tableView.rowHeight - 2 * 14),
                         275.0,
                         24)]
             autorelease];
            [cell.contentView addSubview:learnMoreLabel];
            learnMoreLabel.text = @"Learn More";
            learnMoreLabel.textAlignment = UITextAlignmentCenter;
            learnMoreLabel.backgroundColor = [UIColor clearColor];
            learnMoreLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
            learnMoreLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
        }
        if(indexPath.row == 1)
        {
            UILabel *signUpLabel =
            [[[UILabel alloc]
              initWithFrame:
              CGRectMake(
                         cell.indentationWidth,
                         0.25 * (tableView.rowHeight - 2 * 14),
                         275.0,
                         24)]
             autorelease];
            [cell.contentView addSubview:signUpLabel];
            signUpLabel.text = @"Sign Up for Wallet";
            signUpLabel.textAlignment = UITextAlignmentCenter;
            signUpLabel.backgroundColor = [UIColor clearColor];
            signUpLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
            signUpLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
        }
    }
}

return cell;
}
启用NSZombie后,我会在日志中看到以下消息:

-[PaymentMethodViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x404ae00

以上代码段来自此PaymentMethodViewController。有什么想法吗?

这个问题的第一个答案似乎解决了这个问题