Objective c 无法将UIDocument添加到数组中
如果我试图将一个打开的UIDocument添加到数组中,我将一无所获。我不确定它应该是这样工作的Objective c 无法将UIDocument添加到数组中,objective-c,ios,cocoa-touch,icloud,uidocument,Objective C,Ios,Cocoa Touch,Icloud,Uidocument,如果我试图将一个打开的UIDocument添加到数组中,我将一无所获。我不确定它应该是这样工作的 - (void)loadDocAtURL:(NSURL *)fileURL withClassName:(NSString *)className { id doc = [[NSClassFromString(className) alloc] initWithFileURL:fileURL]; [doc openWithCompletionHandler:^(BOOL suc
- (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返回:我是医生。我的班级是歌曲,我的名字是一首新歌
到目前为止还不错
[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;
}
这两个NSLogs输出:我是一个null,我在表视图中。我的头衔是空的
当我在它被抓取后断点并查看歌曲时,它是完全空的
这让我想到,你不能打开一个UIDocument,把它放在一个数组中,然后把它从数组中拉出来。我说的对吗?如果歌曲是零,那么几乎可以肯定数组是零。我注意到你把它称为_tableList和tableList。我猜它们不是同一个指针 尝试在cellForRowAtIndexPath中使用_tableList。记录它以确认它不是零
您可以在添加数组后立即记录[\u tableList lastObject]来反驳您的数组理论。没错!我的问题是:[tableList objectAtIndex:indexPath.row]。它应该是[self.tableList objectAtIndex:indexath.row]。非常感谢。只要时间允许,我会尽快把这个标记为正确的。