今天折騰了半天的問題,百尺竿頭更進(jìn)一步.
bug現(xiàn)象-在iOS8 系統(tǒng)上出現(xiàn)
1.追根溯源
UIalertcontroller里面添加的textfield旁邊會(huì)有兩個(gè)黑色的框,自己拆視圖(Debug View 就是xcode的功能)發(fā)現(xiàn)里面有一個(gè)tableview.里面cell的背景色是黑色
2.找它
2.1>通過runtime 找不到這個(gè)tableView
unsigned int numIvars; //成員變量個(gè)數(shù)
Ivar *vars = class_copyIvarList(NSClassFromString(@"UIAlertController"), &numIvars);
//Ivar *vars = class_copyIvarList([UIView class], &numIvars);
NSString *key=nil;
for(int i = 0; i < numIvars; i++) {
Ivar thisIvar = vars[i];
key = [NSString stringWithUTF8String:ivar_getName(thisIvar)]; //獲取成員變量的名字
NSLog(@"variable name :%@", key);
key = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)]; //獲取成員變量的數(shù)據(jù)類型
NSLog(@"variable type :%@", key);
}
free(vars);
2.2>循環(huán)遍歷子視圖
首先判斷是不是8的系統(tǒng)
if (SYSTEM_VERSION_LESS_THAN(@"9.0"))
{//循環(huán)遍歷方法
[self wipeOutBlackColorInIOS8WithView:alert.view];
}
-(void)wipeOutBlackColorInIOS8WithView:(UIView *)fatherview
{
for (UIView *view in fatherview.subviews)
{
NSLog(@"view_class:%@",NSStringFromClass([view class]));
if ([NSStringFromClass([view class]) isEqualToString:@"_UIAlertControllerShadowedScrollView"])
{
}
if ([view isKindOfClass:[UITableView class]])
{
UITableView *tableView =(UITableView *)view;
NSInteger sections = tableView.numberOfSections;
for (int section = 0; section < sections; section++)
{
NSInteger rows =[tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++)
{//找到tableView 改變cell背景色
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:kClearColor];
}
}
}
else
{
if (view.subviews.count)
{
[self wipeOutBlackColorInIOS8WithView:view];
}
}
}
}
堅(jiān)持就是勝利