我有一个滑出式 UIView 作为设置面板。该视图有一个容器,其中包含一个表视图控制器。表格视图本身有大约 6 组静态单元格,它们代表各种选项。每个单元格中有几个 UIButton,根据组的不同,它们具有不同的行为。我创建了一个单独的自定义 UIView 子类,它处理每个组中按钮的绘制。首次加载此面板时,我正在为每个组的按钮创建一个字典字典,并为每个组的自定义视图创建一个字典字典(具有匹配的键路径)。
问题是自定义视图似乎只在面板的顶部排列。当我进一步向下滚动到面板的底部时,按钮视图没有排列。对于我的生活,我似乎无法弄清楚这一点。这是面板的图片:
这是我用来在面板加载时初始化设置和布局自定义子视图的代码(在设置面板表视图控制器类中):
- (void)initializeSettings
{
self.buttonStates = nil; // A dictionary of dictionaries with all button states within the panel
self.buttonViews = nil; // A dictionary of dictionaries with all button views (same keyPaths as self.buttonStates).
NSMutableDictionary *buttonStates = [[NSMutableDictionary alloc] init];
NSMutableDictionary *buttonViews = [[NSMutableDictionary alloc] init];
NSArray *btnGroupNames = [self btnGroupNames]; // Array of button group names.
NSArray *btnArrays = [self btnArrays]; // An array of arrays with all buttons.
for(int i = 0; i < [btnArrays count]; i++){
NSArray *outerArray = [btnArrays objectAtIndex: i];
NSString *outerKey = [btnGroupNames objectAtIndex: i];
NSMutableDictionary *innerDicV = [[NSMutableDictionary alloc] init];
NSMutableDictionary *innerDicS = [[NSMutableDictionary alloc] init];
for(UIButton *btn in outerArray){
NSString *innerKey = [btn.titleLabel.text stringByReplacingOccurrencesOfString:@" " withString:@""];
ButtonSelectionView *bsv = [[ButtonSelectionView alloc] initWithFrame: btn.frame];
bsv.alpha = 0.0;
bsv.opaque = NO;
[[btn superview] addSubview: bsv];
[[btn superview] bringSubviewToFront: btn];
[innerDicV addEntriesFromDictionary: @{ innerKey : bsv }];
[innerDicS addEntriesFromDictionary: @{ innerKey : NOT_SELECTED }];
}
[buttonViews setValue: innerDicV forKey: outerKey];
[buttonStates setValue: innerDicS forKey: outerKey];
}
self.buttonViews = buttonViews;
self.buttonStates = buttonStates;
self.previousButtonStates = nil;
self.settingsLoaded = YES;
}
旁注:字典是惰性实例化的。此外,我尝试从 viewDidLoad、viewDidAppear 和 viewDidLayoutSubviews 调用此函数,但无济于事。任何建议将不胜感激,谢谢!