I have a UITableView
for an app I am creating that will show Movie Trailers.
In my RootViewController.h
file I have this code (well all of the relevant code needed is supplied here):
@interface RootViewController : UITableViewController {
NSMutableArray *listOfLinks;
}
In my .m is this code:
- (void)viewDidLoad {
[super viewDidLoad];
listOfLinks = [[NSMutableArray alloc] init];
NSURL *myurl2 = [NSURL URLWithString:@"http://website.com/movietrailers.plist"];
NSDictionary *plistDict2 = [NSDictionary dictionaryWithContentsOfURL:myurl2];
NSArray *plistArray2 = [plistDict2 objectForKey:@"MovieLinks"];
NSDictionary *dic = [NSDictionary dictionaryWithObject:plistArray2 forKey:@"MovieLinks"];
[listOfLinks addObject:dic];
NSLog(@"%@", listOfLinks);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSURL *movieURL = [listOfLinks objectAtIndex:indexPath.row];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}
My plist looks 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">
<dict>
<key>MovieTitles</key>
<array>
<string>Movie 1</string>
<string>Movie 2</string>
</array>
<key>MovieLinks</key>
<array>
<string>http://trailerserver.com/movie1.mp4</string>
<string>http://trailerserver.com/movie2.mp4</string>
</array>
</dict>
</plist>
But I am essentially getting the error that listOfLinks
is empty. The error looks like this:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 0]'
When I NSLog
the array it prints out it's strings. What is the reason for this? Thanks for your help!