UIButton 在 @implementation 下创建。我必须在某些功能后将其删除,但[button removeFromSuperview]
不起作用。我怎样才能删除它?
#import "TabBar.h"
#import "CustomCell.h"
@interface TabBar ()
@end
@implementation TabBar
UILabel *title;
NSString *par;
UIButton *button;
NSMutableArray *backlist;
- (NSString *)documentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject];
}
-(void)tbl_info{
NSString *path = [[self documentsDirectory] stringByAppendingPathComponent:@"icd10.plist"];
self.dataList = [[NSMutableArray alloc] initWithContentsOfFile:path];
for (NSInteger i=[self.dataList count]-1; i>=0;i--) {
NSDictionary *d = [self.dataList objectAtIndex:i];
par=[d objectForKey:@"PARENTID"];
if(![par isEqualToString:self.val])
[self.dataList removeObjectAtIndex:i];
}
}
- (IBAction)ara:(id)sender{
[self tbl_info];
[self.tViewTab reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.dataList count];
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *name= [[self.dataList objectAtIndex:indexPath.row] objectForKey:@"NAME"];
CGSize maxSize = CGSizeMake(320/2, MAXFLOAT);
CGSize labelSize = [name sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
if(labelSize.height>=63)
labelSize.height=63;
return labelSize.height+1;
}
- (UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"cellid";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
{
cell = (CustomCell*)[[[NSBundle mainBundle]
loadNibNamed:@"CustomCell" owner:nil options:nil]
lastObject];
}
NSDictionary *d = [self.dataList objectAtIndex:indexPath.row];
cell.nameLabel.text = [d objectForKey:@"NAME"];
cell.cityLabel.text = [d objectForKey:@"CODE"];
cell.indexPath = indexPath;
CGSize maxSize = CGSizeMake(320/2, MAXFLOAT);
CGSize nameSize = [cell.nameLabel.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
if(nameSize.height>=63)
nameSize.height=63;
cell.nameLabel.frame =CGRectMake(80, 0, 234, nameSize.height);
cell.cityLabel.text = [d objectForKey:@"CODE"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *d = [self.dataList objectAtIndex:indexPath.row];
NSMutableDictionary *backprop = [[NSMutableDictionary alloc] init];
[backprop setObject:self.val forKey:@"id"];
[backprop setObject:title.text forKey:@"name"];
[backlist addObject:backprop];
//back button
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(touchEvent:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:title.text forState:UIControlStateNormal];
button.frame = CGRectMake(02.0, 02.0, 71, 32);
[self.view addSubview:button];
//parent and title label
[title setText:[d objectForKey:@"NAME"]];
self.val=[d objectForKey:@"ID"];
[self tbl_info];
[self.tViewTab reloadData];
}
-(void)touchEvent:(id)sender{
[title setText:[[backlist objectAtIndex:backlist.count-1] objectForKey:@"name" ]];
self.val= [[backlist objectAtIndex:backlist.count-1] objectForKey:@"id"];
[backlist removeObjectAtIndex:backlist.count-1];
if(backlist.count>0)
[button setTitle:[[backlist objectAtIndex:backlist.count-1] objectForKey:@"name" ] forState:UIControlStateNormal];
else
[button removeFromSuperview];
[self tbl_info];
[self.tViewTab reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
backlist =[[NSMutableArray alloc]init];
self.val=@"0";
[self tbl_info];
[self.tViewTab reloadData];
title =[[UILabel alloc]initWithFrame:CGRectMake(79.0, 07.0, 162, 21)];
title.text = @"ICD10 Kod Grupları"; //etc...
[self.view addSubview:title];
[title release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}