行がテーブルビューに追加された後にメソッドを呼び出す必要があり、これを試しています
if (_tableView) {
[self.currentDownloads insertObject:url atIndex:0];
NSLog(@"%@", _currentDownloads);
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
ACDownloadCell *cell = (ACDownloadCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[cell downloadFileAtURL:url];
}
else{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 499) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
[self.currentDownloads insertObject:url atIndex:0];
NSLog(@"%@", _currentDownloads);
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
ACDownloadCell *cell = (ACDownloadCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSLog(@"%@", cell);
[cell downloadFileAtURL:url];
}
ただし、ログに記録する場合はログcell
に記録し(null)
ます。ここで何か間違っていることがわかりますか? これが私のtableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ACDownloadCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ACDownloadCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[ACDownloadCell class]])
{
cell = (ACDownloadCell *)currentObject;
break;
}
}
}
return cell;
}