I am using tutorial (now inaccessible) “UITableView – Searching table view”.
but I really have bad time try to read from plist.
that what I did change:
- (void)viewDidLoad {
[super viewDidLoad];
//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];
TableViewAppDelegate *AppDelegate = (TableViewAppDelegate *)[[UIApplication sharedApplication] delegate];
listOfItems = [AppDelegate.data objectForKey:@"Countries"];
//Initialize the copy array.
copyListOfItems = [[NSMutableArray alloc] init];
//Set the title
self.navigationItem.title = @"Countries";
//Add the search bar
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
}
and this how I read plist from My AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
and this my plist:
<plist version="1.0">
<dict>
<key>Countries</key>
<array>
<array>
<string>USA</string>
</array>
<array>
<string>UK</string>
</array>
</array>
</dict>
</plist>
and I get this error:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[NSCFArray objectForKey:]: unrecognized selector sent to instance 0xe09120′
This assigns a newly allocated mutable array to a member.
This leaks the above array and assigns an autoreleased, immutable array to the member.
Later, when you access listOfItems, it may have been released. Use this:
This all assumes that
[AppDelegate.data objectForKey:@"Countries"]is returning an array. Given the plist, it should, but it is worth double checking.