開いている UIDocument を配列に追加しようとしても、何も得られません。これが機能するはずの方法かもしれませんが、わかりません。
- (void)loadDocAtURL:(NSURL *)fileURL withClassName:(NSString *)className {
id doc = [[NSClassFromString(className) alloc] initWithFileURL:fileURL];
[doc openWithCompletionHandler:^(BOOL success) {
if (!success) {
NSLog(@"Failed to open %@", fileURL);
return;
}
NSLog(@"I'm a doc. My class is %@, my title is %@", NSStringFromClass([doc class]), [doc title]);
dispatch_async(dispatch_get_main_queue(), ^{
//[self addOrUpdateEntryWithURL:fileURL metadata:metadata state:state version:version];
[_tableList addObject:doc];
[self.tableView reloadData];
NSLog(@"%d", _tableList.count);
});
}];
};
その NSLog の戻り値: I'm a doc. 私のクラスは歌です、私のタイトルは新しい歌です
ここまでは順調ですね。
[self.tableView reloadData]、テーブルを正しくリロードし、正しい数のセルが表示されます。空であるだけです。これが理由です:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Song *theSong = [tableList objectAtIndex:indexPath.row];
NSLog(@"I am a %@", NSStringFromClass([theSong class]));
UILabel *titleLabel = (UILabel *)[cell viewWithTag:0];
UILabel *lyricLabel = (UILabel *)[cell viewWithTag:1];
NSLog(@"I'm in the table view. My title is %@", [theSong lyric]);
titleLabel.text = theSong.title;
lyricLabel.text = theSong.lyric;
[theSong closeWithCompletionHandler:^(BOOL success) {
// Check status
if (!success) {
NSLog(@"Failed to close %@", theSong.fileURL);
// Continue anyway...
}
}];
return cell;
}
これら 2 つの NSLogs 出力: I am a (null) and I'm in the table view. 私の役職は (空)
ブレークポイントを指定して、グラブした後に theSong を見ると、完全に空です。
これにより、UIDocument を開いて配列に貼り付け、配列から引き戻すことができないと考えるようになりました。私は正しいですか?