RayManAaa
asked on
Xcode 4 *.plist file.
I am new to xcode 4.2.1 and I am slowly trying to learn how to use it.
I am working on creating a simple table view but I am having a strange problem.
The problem is when I create a new plist file but if I use the sample plist file in the class project it works just fine.
Now I know what you are probably thinking, why don't I use the sample file from the class and move on to the next project. Because the scope of the project was to learn how to create a simple table view along with knowing how to create a new plist file.
The sample file is only there to show you how the finish product should look like.
This is what I have tried so far to trouble shoot this problem.
I have copied the sample plist file and renamed it to something else (test.plist) and deleted all the data in the file and entered my own. Once I did this I edited my viewcontroller.m file and under the -(void) viewDidLoad and made the following changes.
{
NSString *myfile = [[NSBundle mainBundle]
pathForResource:@"test" ofType:@"plist"];
myplists = [[NSArray alloc] initWithContentsOfFile:myf ile];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
When I finished doing this I saved, build and ran the project and the iOS Simulator launched with my own data in the table view.
No problem here.
The problem is when I create my own plist (test2.plist), I do this exactly how the instructor in the video explains. Right click and select 'New File' in the 'choose a template for your new file' window. I select 'Resources' for iOS and select 'property list' and proceed to enter exactly the same data that I have entered into the test.plist.
Once I have completed this I go back to the same file viewcontroller.m file and update the
NSString *myfile with the new test2.plist file that I created, save, build and run but in this case I see nothing in the table view.
No data and no errors, this is the strange part. I get no errors in the build, I would like to think if the build ran successfully that I should see my data.
Any ideas what I may have missed in this video tutorial?
I am working on creating a simple table view but I am having a strange problem.
The problem is when I create a new plist file but if I use the sample plist file in the class project it works just fine.
Now I know what you are probably thinking, why don't I use the sample file from the class and move on to the next project. Because the scope of the project was to learn how to create a simple table view along with knowing how to create a new plist file.
The sample file is only there to show you how the finish product should look like.
This is what I have tried so far to trouble shoot this problem.
I have copied the sample plist file and renamed it to something else (test.plist) and deleted all the data in the file and entered my own. Once I did this I edited my viewcontroller.m file and under the -(void) viewDidLoad and made the following changes.
{
NSString *myfile = [[NSBundle mainBundle]
pathForResource:@"test" ofType:@"plist"];
myplists = [[NSArray alloc] initWithContentsOfFile:myf
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
When I finished doing this I saved, build and ran the project and the iOS Simulator launched with my own data in the table view.
No problem here.
The problem is when I create my own plist (test2.plist), I do this exactly how the instructor in the video explains. Right click and select 'New File' in the 'choose a template for your new file' window. I select 'Resources' for iOS and select 'property list' and proceed to enter exactly the same data that I have entered into the test.plist.
Once I have completed this I go back to the same file viewcontroller.m file and update the
NSString *myfile with the new test2.plist file that I created, save, build and run but in this case I see nothing in the table view.
No data and no errors, this is the strange part. I get no errors in the build, I would like to think if the build ran successfully that I should see my data.
Any ideas what I may have missed in this video tutorial?
Plist is a XML file, I think your new plist differs from the correct plist for a NSArray in some headers. Can you send upload both plists?
ASKER
Your new plist format is usable for NSDictionary not a NSArray. You should modify it as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict> //Change dict to array
<key>Item 0</key> //Eliminate this line
<string>Broken</string>
</dict> //Change dict to array
</plist>
So it will be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>Broken</string>
</array>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict> //Change dict to array
<key>Item 0</key> //Eliminate this line
<string>Broken</string>
</dict> //Change dict to array
</plist>
So it will be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>Broken</string>
</array>
</plist>
ASKER
Wow, it works!
Why didn't the build detect that the new plist format was unusable?
Why didn't the build detect that the new plist format was unusable?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for you help!