Objective c 我得到了3个BTN来设置属性。但是失败了;exc“不良访问”;单击时。我使用ARC在iOS5上运行它,有人能帮我吗?
我获得了3个BTN来设置属性。但单击时出现“exc\u bad\u access”失败。我使用ARC在iOS5上运行它。我使用alloc+init模式,但仍然失败。我不知道为什么Objective c 我得到了3个BTN来设置属性。但是失败了;exc“不良访问”;单击时。我使用ARC在iOS5上运行它,有人能帮我吗?,objective-c,Objective C,我获得了3个BTN来设置属性。但单击时出现“exc\u bad\u access”失败。我使用ARC在iOS5上运行它。我使用alloc+init模式,但仍然失败。我不知道为什么 @property (strong, nonatomic) NSDictionary *testVariableValues; @synthesize testVariableValues = _testVariableValues; - (NSDictionary *)testVariableValues {
@property (strong, nonatomic) NSDictionary *testVariableValues;
@synthesize testVariableValues = _testVariableValues;
- (NSDictionary *)testVariableValues
{
if (!_testVariableValues) {
_testVariableValues = [[NSDictionary alloc] initWithObjectsAndKeys:@"0", @"x",@"0", @"a",@"0", @"b", nil]];
}
return _testVariableValues;
}
- (IBAction)testPressed:(UIButton *)sender
{
if ([@"Test 1" isEqualToString:sender.currentTitle]) {
self.testVariableValues = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"x", @"2", @"a", "3", "b", nil];
} else if([@"Test 2" isEqualToString:sender.currentTitle]) {
self.testVariableValues = [NSDictionary dictionaryWithObjectsAndKeys:@"-4", @"x", @"3", @"a", "4", "b", nil];
} else if([@"Test 3" isEqualToString:sender.currentTitle]) {
self.testVariableValues = nil;
}
}
您的
NSDictionary
已自动删除。尝试应用retain或alloc+init模式
self.testVariableValues =
[[NSDictionary dictionaryWithObjectsAndKeys:@"1", [...], "b", nil]
retain];
或
如果海报未使用ARC,您的回复将解决问题。但我的假设是他是,在这种情况下,你不能明确地调用retain。不过,这需要对海报的结尾进行澄清。很抱歉,我使用了ARC,我尝试了alloc+init,但使用EXC_BAD_访问时仍然失败。你有这个堆栈跟踪吗?如果没有,是否可以在异常上启用断点?
if (!_testVariableValues) {
_testVariableValues = [NSDictionary alloc] initWithObjectsAndKeys:@"0", @"x",@"0", @"a",@"0", @"b", nil];
}