[英]UITableView Cell's expanded view doesn't show subviews?
我在單擊時擴展了一個UITableView單元格。當該單元格擴展時,我必須將一個UIView加載到其中。我的問題是我能夠在少數情況下看到UIView,有時它不顯示? UIView將被加載到每個擴展的單元格中。
擴展是這樣的:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat kExpandedCellHeight =300;
CGFloat normalCellHeight = 94;
if ([self.expandedCells containsObject:indexPath]) {
return kExpandedCellHeight;
}else{
return normalCellHeight;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Cell";
ListCell *cell =(ListCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:self options:nil];
cell = nibs[0];
}
cell.Name.text = [[nameArray objectAtIndex:indexPath.row]valueForKey:@"opName"];
if (isExpanded) {
backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 95, 320,205)];
[backgroundView setBackgroundColor:[UIColor colorWithRed:(235/255) green:(235/255) blue:(235/255) alpha:0.1]];
[cell.contentView addSubview:backgroundView];
container = [[UIView alloc]initWithFrame:CGRectMake(40, 67, 240, 120)];
container.backgroundColor = [UIColor whiteColor];
//I am adding buttons to this scrollview after webservice response,once buttons are loaded I am trying to load the above container on the background view.
container_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 5, 220, 110)];
[container_scrollView setBackgroundColor:[UIColor whiteColor]];
[container addSubview:container_scrollView];
}
return cell;
}
現在我確實從webservice得到響應,同時也添加了按鈕,但是我有時看到加載的容器視圖有時不顯示,這必須是什么原因,是什么原因引起的?
這就是我將容器加載到背景視圖中的方式。
//After container is loaded with buttons.
if(backgroundView){
[backgroundView addsubView:container];
}
聲明的東西:
@interface ListViewController ()
{
UIView *backgroundView;//Used in expanded cell.
UIView *container;
BOOL isExpanded; //I set this to NO in viewDidLoad initially.
UIScrollView *container_scrollView;
}
您應該考慮在情節提要上有兩個不同的單元格或兩個xib文件,每個單元格都有其對應的cellidentifier。 一個將是您的正常單元格,另一個將是您的擴展單元格。 然后,每當用戶點擊一個普通單元格時,您都應該用第二種類型的單元格(擴展單元格)“替換”(重繪)該特定單元格。
更新
要執行單元的更新,可以使用以下任何一種方法。 這里更多
reloadData
reloadRowsAtIndexPaths:withRowAnimation:
reloadSections:withRowAnimation:
這些將導致您的某些“表視圖數據源”委托方法再次被調用,然后應使用一些邏輯來決定要繪制哪種單元格。 快速草稿:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier;
// Here you should implement your custom logic to check if you want a basic or expanded cell.
if (IWantBasicCell) {
cellIdentifier = @"basicCell";
} else {
cellIdentifier = @"expandedCell"
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[cell myCustomLoadInformationMethod:myCustomData];
return cell;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.