我有一個幻燈片UIView,它充當設置面板。視圖中有一個帶有表格視圖控制器的容器。表格視圖本身有大約6組代表各種選項的靜態單元組。每個單元格中都有幾個UIButton,並且取決於組,它們具有不同的行爲。我創建了一個單獨的自定義UIView子類,它處理每個組中按鈕的繪製。當第一次加載此面板時,我將爲每個組的按鈕創建一個字典詞典(針對每個組的自定義視圖的字典詞典(具有匹配的鍵路徑)&)。在整個UITableView中添加幾個自定義子視圖(設置面板)
問題是,自定義視圖只能在面板的頂部顯示。當我向下滾動到面板的底部時,按鈕視圖不排隊。對於我的生活,我似乎無法弄清楚這一點。下面是面板的圖片:
這裏是我使用的初始化設置&佈局自定義子視圖代碼當面板負載(在設置面板表視圖控制器類):
- (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調用此函數,但無濟於事。任何建議將不勝感激,並感謝你!
好的,也許只是簡單的問題:UIButtons在什麼時候知道它們的框架在UITableViewCell中?當我將它們放置在IB中時,我可以如何獲得所有UIButtons的幀(甚至是可見視圖之外的幀)?通過出口集合枚舉似乎給了我如上圖所示的相同結果。 –