当我点击UIAlertView的OK按钮时,我需要更改视图的背景颜色,其默认颜色为白色,因此每次用户点击OK,我需要在两种颜色之间交替,例如白色和红色:
-(void)changeColor{
if([self.view.backgroundColor isEqual: [UIColor whiteColor]]){
self.view.backgroundColor=[UIColor redColor];
}else {
self.view.backgroundColor=[UIColor whiteColor];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,在第一次OK点击时,颜色应该变成红色,但是它没有得到红色,所以我需要第二次单击OK按钮以获得带红色的视图背景颜色.我错过了第一次改变颜色的东西吗?
这是alertView:didDismissWithButtonIndex委托方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
//NSLog(@"It's Ok button which has been clicked");
//Do whatever you want, commonly call to another function like so:
[self changeColor];
}else
if (buttonIndex==1) {
//NSLog(@"It's Cancel button which has been clicked");
}
}
Run Code Online (Sandbox Code Playgroud)
它可能与返回的"白色"不同[UIColor whiteColor].如果您在IB中选择白色作为视图并进行记录,则会得到: UIDeviceRGBColorSpace 1 1 1 1
如果您然后将颜色设置为[UIColor whiteColor],并再次记录,您会得到:UIDeviceWhiteColorSpace 1 1
| 归档时间: |
|
| 查看次数: |
2718 次 |
| 最近记录: |