1
如果我嘗試將打開的UIDocument添加到數組中,我什麼也沒有得到。這可能是它應該如何工作,我不確定。無法將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返回:我是一個文檔。我的班是宋,我的標題是新歌
到目前爲止好。
[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 objectAtIndex:indexPath.row]。它應該是[self.tableList objectAtIndex:indexPath.row]。謝謝!只要時間允許,我會將其標記爲正確。 – tharris