0
Im receiving the next error:

キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。理由: ' * -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'

.h file
    @property(nonatomic, retain) NSMutableArray *arrayOfBenchmarks;

.m file
- (void)viewDidLoad
{
    [super viewDidLoad];

    arrayOfBenchmarks = [[NSMutableArray alloc]init];
    arrayOfBenchmarks = [self.currentDrill valueForKey:@"benchmarks"];

    for (int i=0; i<[arrayOfBenchmarks count]; i++) {

        UIButton *benchmarkButton = [UIButton buttonWithType:UIButtonTypeCustom];
        benchmarkButton.tag = i;
        benchmarkButton.frame = CGRectMake(40,20+(i*55) , 240, 50);
        [benchmarkButton setBackgroundImage:[UIImage imageNamed:@"red_color.png"] forState:UIControlStateNormal];
        benchmarkButton.titleLabel.textColor = [UIColor blackColor];
        benchmarkButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        benchmarkButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        NSString *tempString = [[[arrayOfBenchmarks objectAtIndex:i] valueForKey:@"benchmarkTitle"]  stringByAppendingString:@"\n"];
        [benchmarkButton setTitle:[tempString stringByAppendingString:@"00:00:00"] forState:UIControlStateNormal];
        [benchmarkButton addTarget:self action:@selector(onTapBenchmarkButton:)
             forControlEvents:UIControlEventTouchUpInside];
//        benchmarkButton.enabled = false;

        self.btn_scrollView.contentSize = CGSizeMake(0, 50+[arrayOfBenchmarks count]*50);
        [arrayOfButtons addObject:benchmarkButton];
        [self.btn_scrollView addSubview:benchmarkButton];
        dynamicBtnCounter++;
    }
}

- (void)onTapBenchmarkButton:(id)sender{

    int index = [sender tag];
    NSLog(@"index %i", index);
    NSString *tempString = [[[arrayOfBenchmarks objectAtIndex:index] valueForKey:@"benchmarkTitle"]  stringByAppendingString:@"\n"];
    [sender setTitle:[tempString stringByAppendingString:[timerLabel text]] forState:UIControlStateNormal];
    [sender setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"green_color.png"]]];
//    [sender setBackgroundImage:[UIImage imageNamed:@"green_color.png"]];
    NSMutableDictionary *benchmark = (NSMutableDictionary *)[arrayOfBenchmarks objectAtIndex:index];
    [benchmark setValue:[timerLabel text] forKey:@"benchmarkPerformedTimer"]; //giving exception at this line
    [sender setEnabled:NO];

}

これが私のベンチマーククラスです

@interface Benchmark : NSObject

@property (nonatomic, retain) NSString *bid;
@property (nonatomic, retain) NSString *benchmarkTitle;
@property (nonatomic, retain) NSString *benchmarkDescription;
@property (nonatomic, retain) NSString *benchmarkPerformedTimer;

-(id)initWithCoder: (NSCoder *)coder;
-(void)encodeWithCoder:(NSCoder *)encoder;

@end
4

1 に答える 1

0

可変コピーを追加することでそれを行いました:

NSMutableDictionary *benchmark = (NSMutableDictionary *)[[arrayOfBenchmarks objectAtIndex:index] mutableCopy];
    [benchmark setValue:[timerLabel text] forKey:@"benchmarkPerformedTimer"];
于 2013-03-19T10:27:33.640 に答える