ios 内存管理

本文介绍了一个iOS应用中视图控制器(PersonCenterViewController)的正确使用方式,特别是导航控制器的推送和释放过程,避免因不当操作导致的内存泄漏问题。同时展示了自定义scrollView与tableView的具体实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用导航控制器时,如果返回的时候蹦,那就是因为dealloc里面重复释放了。

PersonCenterViewController *personCenterVC = [[PersonCenterViewController alloc]initWithNibName:@"PersonCenterViewController" bundle:nil];
    [self.navigationController pushViewController:personCenterVC animated:YES];
    [personCenterVC release];

//创建自己的scrollview.
    myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 180)];
    self.myScrollView.backgroundColor = [UIColor whiteColor];
    self.myScrollView.contentSize=CGSizeMake(320, 200);
    UIImageView *shopImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 180)];
    shopImageView.image = [UIImage imageNamed:@"shopImageDemo.png"];
    [self.myScrollView addSubview:shopImageView];
    [self.view addSubview:self.myScrollView];
    self.myScrollView.scrollEnabled = NO;
    [myScrollView release];
    [shopImageView release];
   
    //创建自己的tableview.
    myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 180, 320, 300) style:UITableViewStyleGrouped];
    self.dataArray=[NSMutableArray arrayWithObjects:@"店铺简介",@"经典发型",@"地图位置",@"热线电话:010-66228989", nil];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.myTableView.separatorColor = [UIColor grayColor];
    self.myTableView.dataSource=self;
    self.myTableView.delegate=self;
    self.myTableView.backgroundView = nil;
    self.myTableView.scrollEnabled = NO;
    self.myTableView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.myTableView];
    [myTableView release];

 

 //section里面的内容。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *shopNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, 100, 30)];
    shopNameLabel.backgroundColor = [UIColor clearColor];
    shopNameLabel.text = @"金融街店";
    shopNameLabel.textColor = [UIColor whiteColor];
    
    UILabel *shopAddressLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 300, 20)];
    shopAddressLabel.backgroundColor = [UIColor clearColor];
    shopAddressLabel.text = @"北京市西城区金融大街甲26号顺成饭店首层";
    [shopAddressLabel setFont:[UIFont fontWithName:@"Arial" size:13]];
    shopAddressLabel.textColor = [UIColor whiteColor];
    
    UIView *sectionView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 70)]autorelease];
    [sectionView setBackgroundColor:[UIColor grayColor]];
    [sectionView addSubview:shopNameLabel];
    [sectionView addSubview:shopAddressLabel];
    [shopNameLabel release];
    [shopAddressLabel release];
//    [sectionView release];//这里不能直接release了,只能autorelease就行了。
    return sectionView;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值