在适配ios7时需要用到自定义对话框,下载了CustomIOS7AlertView,使用时经常遇到程序死机崩溃,定位问题发现出在[CustomIOS7AlertView countScreenSize]这个函数的调用上。
百思不得其解,后来把[buttonTitles count]注释了才好。这才想起来,好像用的时候没有给buttonTitles赋值,用的默认的Close按钮,所以这里取不到数值,导致程序崩溃的。
以下是注释后的函数。
- (CGSize)countScreenSize
{
// && [buttonTitles count] > 0
if (buttonTitles!=NULL) {
buttonHeight = kCustomIOS7AlertViewDefaultButtonHeight;
buttonSpacerHeight = kCustomIOS7AlertViewDefaultButtonSpacerHeight;
} else {
buttonHeight = 0;
buttonSpacerHeight = 0;
}
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
CGFloat tmp = screenWidth;
screenWidth = screenHeight;
screenHeight = tmp;
}
return CGSizeMake(screenWidth, screenHeight);
}