我目前正在開發一個應用程序,如果用戶點擊一個按鈕,它會將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