I have a UIView
inside a UITableViewCell
(Let's say a container).I want to add another UIView
as a subView to this container.However I am able to load the subView but it doesn't show up in every cell.The reason I am doing so is because I want to load two different UIViews from nib files onto the container depending upon segment control click.So here's what I am doing.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Cell";
static NSString *expandedCellIdentifier = @"ExpandedCell";
if (!isExpanded) {
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 = [[bArray objectAtIndex:indexPath.row]valueForKey:@"Name"];
return cell;
}
else{
expCell =(ExpandedCell*) [tableView dequeueReusableCellWithIdentifier:expandedCellIdentifier]; //Made this global iVar to refrence it from other methods.
if (expCell==nil) {
NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ExpandedCell" owner:self options:nil];
expCell = nibs[0];
lDView = [[[NSBundle mainBundle]loadNibNamed:@"lDView" owner:self options:nil]firstObject]; //lDView is a UIView subclass.
[lDView setFrame:CGRectMake(0, 0, 225, 90)];
[lDView setBackgroundColor:[UIColor grayColor]];
//more code.
}
return expCell;
}
return nil;
}
Now I add this 'lDView' to the subView after populating it with some buttons like this.
-(void)addButtons{
//Add buttons here
[lDView.containerScrollView addSubview:btn];
[expandedCell.containerView addSubview:lDView]; //Doesn't add it to each and every table View cell.Its loading sometimes and sometimes doesn't show up.