【发布时间】:2012-08-28 14:34:31
【问题描述】:
我目前正在开发一个应用程序,如果用户单击一个按钮,它会将 buttonPressed 设置为“YES”并转到一个新视图。在这个新视图中,您可以选择颜色,一旦选择了颜色,它将返回上一个视图,并在单击的按钮的背景上显示其选择的颜色。
我在运行代码时无法访问布尔值并收到 SIGBART 错误。 我在这里做错了什么? 在我的 ChangeClothesViewController 中
@property (assign, readwrite) BOOL pantsPressedBool;
@synthesize pantsPressedBool = _pantsPressedBool;
- (IBAction)pantsPressed:(UIButton *)sender {
ChooseColorsViewController *color = [[ChooseColorsViewController alloc] initWithNibName:@"ChooseColorsViewController" bundle:nil];
[self.navigationController pushViewController:color animated:YES];
//AppDelegate *passColors = (AppDelegate *)[[UIApplication sharedApplication]delegate];
//this code above does nothing and is not even needed. I was testing something out and forgot to take it out
_pantsPressedBool = YES;
}
在我的 RectangleView 内部(这是我在按钮后面制作一个矩形来为按钮制作背景的地方)
- (void)drawRect:(CGRect)rect
{
//custom delegate
AppDelegate *passColors = (AppDelegate *)[[UIApplication sharedApplication]delegate];
changeClothes *whichButton = (changeClothes *)[[UIApplication sharedApplication]delegate];
for (int i=0; i < [passColors.getColors count]; i++) {
if ([[passColors.getColors objectAtIndex:i] isEqualToString: @"Black"]) {
NSLog(@"what button: %c", whichButton.pantsPressedBool); //HERE
if (whichButton.pantsPressedBool == YES ) { //AND HERE is where I get the SIGABRT error
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
//CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 0.5); //CGContextRef, Red, Green, Blue, Alpha
rect = CGRectMake(20, 20, 40, 80); //x, y, width, height
CGContextFillRect(context, rect); //CGContextRef, CGRect
}
}
}
}
一如既往,任何帮助都将不胜感激。
提前致谢。
[编辑]
所以我正在尝试不同的东西。
- (IBAction)pantsPressed:(UIButton *)sender {
ChooseColorsViewController *color = [[ChooseColorsViewController alloc] initWithNibName:@"ChooseColorsViewController" bundle:nil];
[self.navigationController pushViewController:color animated:YES];
AppDelegate *chosenButton = (AppDelegate *)[[UIApplication sharedApplication]delegate];
chosenButton.pantsButton = YES;
}
所以在我的 AppDelegate 中,我有
@property (assign, readwrite) BOOL pantsButton;
@synthesize pantsButton = _pantsButton;
如果单击该按钮,我正在尝试将 AppDelegate 中的 BOOL 变量(pantsButton)设置为“YES”,并设置 if 语句
if ([chosenButton.pantsButton == YES]) {
do something
}
【问题讨论】:
-
“changeClothes”是我的“ChangeClothesViewController”。我知道这违反了 Apple 的标准命名约定,但我还没有修复它。但我确实知道这一点,并将在未来做出改变
-
你有一个pantsPressed 属性和一个pantsPressed 操作方法,这不太好:) 重命名其中一个,然后重试
-
大声笑哦,直到现在我才意识到这一点。修复它但仍然收到 SIGABRT 错误
-
你能提供更多的错误细节吗?调试器说什么?
-
这是我的输出框中的内容。 AppDelegatepantPressedBool]:无法识别的选择器发送到实例 0x6e4d170
标签: iphone objective-c uiviewcontroller boolean