开发者

Data saving code is working on simulator but not on iphone

开发者 https://www.devze.com 2023-04-13 09:20 出处:网络
+(NSString*)pathoffile2{ NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+(NSString*)pathoffile2{

    NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    开发者_运维知识库NSString *documentfolder2 = [path2 objectAtIndex:0];
    return [documentfolder2 stringByAppendingFormat:@"myuserlist"];
    }

-(IBAction)buttonpressed:(id)sender{

NSString *str = [[NSString alloc]init];

str = txt1.text;

NSArray *arr = [[NSArray alloc]initWithObjects:str, nil];

NSString *filepath = [Test4 pathoffile2];

[arr writeToFile:filepath atomically:YES];

NSLog(@"arr is %@",arr);

}

This code is running well in simulator, it saves data and retrieve data in simulator but not working on actual iPhone, actually directory is created in actual device but not saving data in device ,It saves null value, What is the problem, I can't understand, everything is ok but not working on device. My Xcode version is 4.3 and device iOS is 4.3.3 is their


All you need is add a slash by using an appropriate method - replace your return value with this:

return [documentfolder2 stringByAppendingPathComponent:@"myuserlist"];

0

精彩评论

暂无评论...
验证码 换一张
取 消