[英]How Pre Expanded UITableview which is again having UITableview in UITableCell in IOS 8
[英]iOS Set UITableView Expanded Initially
我有一個UITableView具有可擴展的自定義單元格。 可以擴展多個單元。 為此,我有一個數組expandArray,其中存儲了所有已擴展單元格的indexPath。 最初,所有單元格都崩潰了。 我想在開始時將所有單元格擴展。 這是我的cellForRowAtIndexPath代碼:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// VISITORS LISTS TV
NSUInteger count = 0;
VisitorsListsCell *vcell = (VisitorsListsCell *) [tableView dequeueReusableCellWithIdentifier:@"VisitorsListsCell"];
if (vcell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"VisitorsListsCell" owner:self options:nil];
vcell = [nib objectAtIndex:0];
}
// Button - Round Corners
[vcell button].layer.cornerRadius = 5;
[vcell button].contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
NSString *text = [visistorsList objectAtIndex:indexPath.row];
// SET PROPERTIES OF CELL
// ....
if ([expandedArray containsObject:indexPath]) {
// Do expanded cell stuff
[vcell setButtonText:[visistorsList objectAtIndex:indexPath.row] withCount:(int)count isExpanded:YES];
[vcell.button setImage:[UIImage imageNamed:@"arrowup.png"] forState:UIControlStateNormal ];
} else {
[vcell setButtonText:[visistorsList objectAtIndex:indexPath.row] withCount:(int)count isExpanded:NO];
[vcell.button setImage:[UIImage imageNamed:@"arrowdown.png"] forState:UIControlStateNormal ];
}
[[vcell listsTableView] reloadData];
return vcell;
}
我想要的是在頁面加載后,所有單元格都展開了。 我相信為此,我需要將每個單元格的indexPath添加到expandedArray。 但是,僅在初始運行時,如何添加indexPath? 我找不到實現它的方法。
是否有任何線索。 或通過其他任何方式實現目標。 非常感謝您的幫助。 謝謝。
要將indexPath添加到擴展數組中,應使用以下代碼。 但是更簡單的方法是使用-numberOfSections
和numberOfRowsInSection:
使用的相同方法。 使用tableView委托不是一個好方法。
- (void)viewDidLoad {
self.expandedArray = [NSMutableArray new];
for (int itSection=0; itSection<[self.tableView numberOfSections]; itSection++) {
for (int itRow=0; itRow<[self.tableView numberOfRowsInSection:itSection]; itRow++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:itRow inSection:itSection];
[self.expandedArray addObject:indexPath];
}
}
}
順便說一句:從xib實現單元的正確方法:
- (void)viewDidLoad {
....
UINib *nib = [UINib nibWithNibName:NSStringFromClass([VisitorsListsCell class]) bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"VisitorsListsCell"];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.