NSstring和“Zeros”的第3个视图控件

时间:2011-06-08 19:50:58

标签: iphone xcode

我遇到零问题

如果我的叮咬包含零或没有任何内容,则第3个控制视图会使应用程序崩溃。

任何想法

- (void)viewDidLoad {
    appDelegate= (TemplateIponeAppDelegate *)[UIApplication sharedApplication].delegate;

    if ([MFMailComposeViewController canSendMail])
        mailButton.enabled = YES;

    rResults.text = [NSString stringWithFormat:@"R Resultes:  %d",appDelegate.RCount];
    bResults.text=[NSString stringWithFormat:  @"B Resultes:  %d",appDelegate.BCount];
    pResults.text=[NSString stringWithFormat:  @"P Resultes:  %d",appDelegate.PCount];
    fResults.text=[NSString stringWithFormat:  @"F Resultes:  %d",appDelegate.FCount];

    totalResults.text=[NSString stringWithFormat:  @"Total R-P-B:  %d",appDelegate.TotalPressed];

    rightCount = appDelegate.RCount + appDelegate.BCount+appDelegate.PCount;

    grandtotal.text=[NSString stringWithFormat:  @"Total :  %d",rightCount];

    ratiocount= (appDelegate.RCount + appDelegate.BCount+appDelegate.PCount) /appDelegate.FCount;   
    ratiototal.text = [NSString stringWithFormat:  @"Total :  %d",appDelegate.FCount];

    [super viewDidLoad];

1 个答案:

答案 0 :(得分:0)

你的问题就在这一行,

ratiocount= (appDelegate.RCount + appDelegate.BCount+appDelegate.PCount) /appDelegate.FCount; 

如果appDelegate.FCount为零,那么这将导致错误。你应该对它进行某种检查。