我有在使用隨機順序顯示下面有三個UIButtons:無法掩蓋創建的UIButton
NSMutableArray *indexArray = [NSMutableArray arrayWithObjects:
[NSValue valueWithCGRect:CGRectMake(20, 187, 280, 44)],
[NSValue valueWithCGRect:CGRectMake(20, 258, 280, 44)],
[NSValue valueWithCGRect:CGRectMake(20, 330, 280, 44)], nil];
//Randomize the array
NSUInteger count = [indexArray count];
for (NSUInteger i = 0; i < count; ++i) {
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[indexArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}
//Assign the frames
button1.frame = [((NSValue *)[indexArray objectAtIndex:0]) CGRectValue];
button2.frame = [((NSValue *)[indexArray objectAtIndex:1]) CGRectValue];
button3.frame = [((NSValue *)[indexArray objectAtIndex:2]) CGRectValue];
出於某種原因,我一個無法隱藏這些按鈕後,便顯示了一些項目。我試過了,例如
button1.hidden = YES;還有 [self.button1.hidden = YES];
任何想法?非常感激任何的幫助。
Jamie
你應該顯示你究竟如何試圖隱藏他們...在哪裏,在哪個方法?什麼時候? – sergio
我創建了一個小測驗應用程序。問題被加載到UILabel中,並從plist(通過NSMultableArray)加載到這些UIButtons中,當一定數量的問題被回答後,結果顯示出來,問題和按鈕應該消失。要做到這一點,我使用這個: 'if([questions count] == 11){button1.hidden = YES; button2.hidden = YES; button3.hidden = YES}'。我很困惑,爲什麼這些UIButtons不隱瞞。 –