我目前正在开发一个应用程序,如果用户点击一个按钮,它会将button按钮设置为“YES”并转到新视图。在这个新的视图中,您可以选择颜色,并且一旦选择了颜色,它将返回到前一个视图,并在被点击的按钮的背景上以其选择的颜色显示。如何将BOOL值从一个视图传递到另一个视图c
我在运行代码时无法访问布尔值并出现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;
我想设置布尔变量(pantsButton)中的AppDelegate里面“YES”,如果被点击的按钮,使if语句这样
if ([chosenButton.pantsButton == YES]) {
do something
}
“changeClothes”是我的“ChangeClothesViewController”。我知道这违背了苹果的标准命名约定,但我还没有修复它。但我知道这件事,并会在未来做出改变 – Jay
你有一个裤子压力属性和一个裤子压制的动作方法,这不能是好的:)重命名其中一个,然后再试一次 – Asciiom
哈哈,我甚至没有意识到,直到现在。修复它,但仍然得到SIGABRT错误 – Jay