UITableView
映画の予告編を表示するアプリを作成しています。
私のRootViewController.h
ファイルには次のコードがあります(必要な関連コードはすべてここに提供されています):
@interface RootViewController : UITableViewController {
NSMutableArray *listOfLinks;
}
私の .m には次のコードがあります。
- (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];
}
私の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>
<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>
しかし、本質的にlistOfLinks
空のエラーが発生しています。エラーは次のようになります。
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 0]'
NSLog
配列を出力すると、それは文字列です。これの理由は何ですか?ご協力いただきありがとうございます!