在将一行添加到表视图后,我需要调用一个方法,并且正在尝试这个
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;
}