iOS中自动释放问题?(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-26 21:59 点击:次
//path成员变量,文件路径-自动释放对象
path=[docstr stringByAppendingPathComponent:@"1.png"];
//调用方法,path做参数
[self saveData:path];
//分割线
-(void)saveData:(NSString *)filePath
{
//data读取内容
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"IMG_1340" ofType:@"PNG"];
NSData *data= [NSData dataWithContentsOfFile:imagePath];
//用path去保存data
[data writeToFile:filePath atomically:NO];
} 例子2,这么写,也没问题,文件能保存。或者[self saveData:path]; 改成[self saveData]; saveData方法不传入参数,用成员变量path代替filePath的作用,这么写,也没问题。[html] view plaincopyprint? //例子3
NSArray*patharray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*docstr=[patharray objectAtIndex:0];
//path成员变量,文件路径-自动释放对象
path=[docstr stringByAppendingPathComponent:@"1.png"];
//创建按钮
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 100, 100)];
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
-(void)saveData
{
//data读取内容
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"IMG_1340" ofType:@"PNG"];
NSData *data= [NSData dataWithContentsOfFile:imagePath];
//用path去保存data
[data writeToFile:path atomically:NO];
}
//例子3
NSArray*patharray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*docstr=[patharray objectAtIndex:0];
//path成员变量,文件路径-自动释放对象
path=[docstr stringByAppendingPathComponent:@"1.png"];
//创建按钮
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 100, 100)];
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- iphone开发基础三和c语言混编
- 深入理解iPhone静态库(手把手教你iphone开发
- Cocoa Core Competencies 的Object creation 和IOS面试题示例
- (iOS-iap防护)验证用户付费收据,拒绝iap
- ios 时间定时器 NSTimer应用demo
- iphone-使用TextField及关闭键盘(useing TextField for in
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的
- iOS文件存磁盘的设想
- iPhone开发 调用阿asp.net程序的webservice
- iPhone开发 文件的增加删除查询
新闻点评
新闻关注排行榜
热门推荐
最新推荐