Thread1:程序接收信号:“SIGABRT”

时间:2011-12-16 13:49:11

标签: iphone xcode4.2

项目构建正常,但是一旦应用程序尝试运行它就会崩溃:

它(错误)已经显示如下。

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
                    // here i got Thread1: Program received signal: "SIGBRT" 
    }
}

我的代码是:

(ⅰ)

(我已经声明了collecter实例并导入了collector.h)

#import <UIKit/UIKit.h>
#import "Collector.h"

@interface ViewController : UIViewController{
    Collector *model;
    IBOutlet UILabel *totalStrings;
    IBOutlet UILabel *totalNumbers;
}

-(void)collect:(UIButton *)sender;

@end

(ⅱ)

#import "ViewController.h"
#import "Collector.h"

@implementation ViewController

-(void)updateUI
{
    totalNumbers.text = [NSString stringWithFormat:@"%d",model.totalNumberCount];
    totalStrings.text = [NSString stringWithFormat:@"%d",model.totalStringCount];
}

-(IBAction)collect:(UIButton *)sender
{
    if(!model) model = [[Collector alloc] init];
    double doubleValue = [sender.titleLabel.text doubleValue];
    if (doubleValue) {
        [model collect:[NSNumber numberWithDouble:doubleValue]];
    } else{
        [model collect:sender.titleLabel.text];
    }
    [self updateUI];
}

@end

(III)

#import <Foundation/Foundation.h>

@interface Collector : NSObject{
    NSMutableDictionary *counts;

}
-(void)collect:(id)anObject;
@property (readonly) int totalStringCount;
@property (readonly) int totalNumberCount;

@end

(IV)

#import "Collector.h"

@interface Collector()

@property (readonly) NSMutableDictionary *counts;
@end

@implementation Collector

-(NSMutableDictionary *)counts
{
    if (!counts) {
        counts = [[NSMutableDictionary alloc] init];
    }
    return counts; 
}

-(void)collect:(id)anObject
{
    if ([anObject isKindOfClass:[NSString class]] || [anObject isKindOfClass:[NSNumber class]] ) {
        NSNumber *existingCount = [self.counts objectForKey:anObject];
        [self.counts setObject:[NSNumber numberWithInt: [existingCount intValue] + 1] forKey:anObject];

    }
}

- (int) totalStringCount
{
    int total = 0;
    for (id key in self.counts) {
        if ([key isKindOfClass:[NSString class]]) {
            total +=[[self.counts objectForKey:key] intValue];
        }
    }
    return total;
}

-(int)totalNumberCount
{
    int total = 0;
    for (id key in self.counts) {
        if ([key isKindOfClass:[NSNumber class]]) {
            total +=[[self.counts objectForKey:key] intValue];
        }
    }
    return total;
}

@end

您认为导致此问题的原因是什么?

1 个答案:

答案 0 :(得分:1)

查看此帖子如何设置NSZombieEnabled。这将显示有关崩溃的更多详细信息,可帮助您调试问题:

App crash only on iPhone Device and not in Simulator