Hi guys,
I have a little table that works pretty well. But I was told to remove my subviews at some stage incase the call to drawn the table happens again for whatever reason. I was told it can be handled using removeFromSuperview.
Where and how should i handle this? I need to use tags to identify the cells or views?
Here is my code to create my views.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
[cell setFont:[UIFont systemFontOfSize:10.0]];
if (indexPath.row == 0)
{
[cell setText:@"Show only Airports"];
showAirportsOnlySegment = [ [ UISegmentedControl alloc ] initWithFrame:
CGRectMake(100, 4, 80, 28) ];
[ showAirportsOnlySegment insertSegmentWithTitle: @"Yes" atIndex: 0
animated: NO ];
[ showAirportsOnlySegment insertSegmentWithTitle: @"No" atIndex: 1 animated:
NO ];
showAirportsOnlySegment.selectedSegmentIndex = 0;
showAirportsOnlySegment.segmentedControlStyle = UISegmentedControlStyleBar;
showAirportsOnlySegment.tag = 1;
showAirportsOnlySegment.enabled = YES;
[showAirportsOnlySegment addTarget:self action:@selector(airConOnOffAction:)
forControlEvents:UIControlEventValueChanged];
[ cell addSubview: showAirportsOnlySegment ];
[self.view bringSubviewToFront:showAirportsOnlySegment];
[showAirportsOnlySegment release];
}
else if (indexPath.row == 1)
{
[cell setText:@"Air Con?"];
airConSegment = [ [ UISegmentedControl alloc ] initWithFrame:
CGRectMake(100, 4, 80, 28) ];
[ airConSegment insertSegmentWithTitle: @"Yes" atIndex: 0 animated: NO ];
[ airConSegment insertSegmentWithTitle: @"No" atIndex: 1 animated: NO ];
airConSegment.selectedSegmentIndex = 0;
airConSegment.segmentedControlStyle = UISegmentedControlStyleBar;
airConSegment.tag = 2;
[airConSegment addTarget:self action:@selector(airConOnOffAction:)
forControlEvents:UIControlEventValueChanged];
airConSegment.enabled = YES;
[ cell addSubview: airConSegment ];
[self.view bringSubviewToFront:airConSegment];
[airConSegment release];
}
return cell;
}
Can anybody advise how to handle the remove the subviews?
Many THanks -Code