//function to write into plist
-(void)WriteFileToPlist:(int) num
{
//write everything in the plist
NSString *errorDesc;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:strArray format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
if (plistData) {
[plistData writeToFile:[self savePathForFile:num] atomically:YES];
}
}
//save the path
-(NSString *) savePathForFile:(int) num
{
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"myPlist%d.plist",num]];
}
//get the data from plist
- (NSArray *) GetFileDataFromPlist:(NSString *) fileName
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
//see if Data.plist exists in the Documents directory
if (![fileManager fileExistsAtPath:[self savePath:fileName] ]) {
[fileManager copyItemAtPath:path toPath:[self savePath:@""] error:nil];
}
NSData *plistData = [[NSFileManager defaultManager] contentsAtPath:[self savePath:fileName]];
NSString *error; NSPropertyListFormat format;
NSArray *heats = [NSPropertyListSerialization propertyListFromData:plistData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
if (!heats) {
NSLog(@"Failed to read myPlist. Error: %@", error);
[error release];
}
return heats;
}
//getting the data form the saved path.
-(NSString *) savePath:(NSString *) fileName
{
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"myPlist%@.plist",fileName]];
}
2番目のボタンをタップすると、スーパービューから最初のボタンビューが削除され、2番目のボタンクリックにリンクされたビューが読み込まれます。
あなたはpresentModalViewControllerを使用してビューを提示することができます。..
を私はこれが役立つことを願っています。
優秀、ありがとうございます –
@VinodVishwakarmaありがとう、plsは正解とマークします。 –