Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone cellforrowatinexpath返回nil_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone cellforrowatinexpath返回nil

Iphone cellforrowatinexpath返回nil,iphone,ios,uitableview,Iphone,Ios,Uitableview,我试图从表视图中获取一个特定的单元格,以便更改其标签并停止活动指示器 我遇到的问题是cellforrowatinexpath返回nil 我的表视图只有一行 代码: - (id) initWithNibName: (NSString*) nibNameOrNil bundle: (NSBundle*) nibBundleOrNil { self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (

我试图从表视图中获取一个特定的单元格,以便更改其标签并停止活动指示器

我遇到的问题是
cellforrowatinexpath
返回nil

我的表视图只有一行

代码:

- (id) initWithNibName: (NSString*) nibNameOrNil bundle: (NSBundle*) nibBundleOrNil
{
    self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];

    if (self) 
    {
        numberOfRows = 1;
    }

    return self;
}

- (NSInteger) tableView: (UITableView*) tableView numberOfRowsInSection: (NSInteger) section
{
    return numberOfRows;
}

-(void) stopCellIndicator
{

    LiveUserFeedCell* cell = (LiveUserFeedCell*)[self.liveFeed cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];  
    [cell.activityIndicator stopAnimating];
    cell.middleLabel.text = @"N/a";
}

- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath
{
    static NSString *CellIdentifier = @"UserFeedCell";


    LiveUserFeedCell *cell = (LiveUserFeedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"LiveUserFeedCell" owner:self options:nil];
        cell = (LiveUserFeedCell *)[nib objectAtIndex:0];
    }

    [cell.imgView setImage:[TUNinePatchCache imageOfSize:cell.imgView.frame.size forNinePatchNamed:@"bg_home_newsfeed_normal"]];


    if (shouldDisplayLoading == NO)
    {
        NSArray* songs = homeScreen.recentPlaybacks.songs;
        TWSong* song = [songs objectAtIndex:index];
        cell.middleLabel.text = @"";
        [cell.activityIndicator stopAnimating];

        UIFont *font = [UIFont fontWithName:@"Trebuchet MS" size:14];                       

        NSString* kText =[NSString stringWithFormat:@"<b>%@</b> is listening to %@ by %@",song.user,song.title,song.artist];

        for(int i = 14; i > 0; i=i-1)
        {
            // Set the new font size.
            font = [font fontWithSize:i];
            // You can log the size you're trying: NSLog(@"Trying size: %u", i);

            /* This step is important: We make a constraint box 
             using only the fixed WIDTH of the UILabel. The height will
             be checked later. */ 
            CGSize constraintSize = CGSizeMake(cell.isWatching.frame.size.width, MAXFLOAT);

            // This step checks how tall the label would be with the desired font.
            CGSize labelSize = [kText sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

            /* Here is where you use the height requirement!
             Set the value in the if statement to the height of your UILabel
             If the label fits into your required height, it will break the loop
             and use that font size. */
            if(labelSize.height <= cell.isWatching.frame.size.height)
                break;
        }



        cell.isWatching.font = font;
        cell.isWatching.text = [TTStyledText textFromXHTML:kText lineBreaks:YES URLs:YES];
        cell.isWatching.textAlignment = UITextAlignmentCenter;

        ++index;
        if (index == [songs count])
            index=0;

    }
    else
    {       
        [cell.activityIndicator startAnimating];
    }

    return cell;
}
你知道怎么解决这个问题吗?(可能默认的第一个单元格不在第0行第0节?

尝试使用:

[self.livFeed beginUpdates];   
LiveUserFeedCell* cell = (LiveUserFeedCell*)[self.liveFeed cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];  
[cell.activityIndicator stopAnimating];
cell.middleLabel.text = @"N/a";
[self.liveFeed endUpdates];

显然,问题是在我查询单元格时,tableView尚未配置。

虽然我遇到过类似的情况,但您已经解决了这个问题,因此我向您展示了我所做的:

NSArray *cells = [contactsTable visibleCells];

    UITableViewCell *cell = nil;
    NSIndexPath *path = [param objectAtIndex:1];
    for (UITableViewCell *aCell in cells) {
        NSIndexPath *aPath = [contactsTable indexPathForCell:aCell];

        if ([aPath isEqual:path]) {
            cell = aCell;
        }
    }

奇怪,但经过数小时的尝试和错误后效果良好。

我遇到了同样的问题,CellForRowatineXpath返回零,原因相当愚蠢。在
tableView:cellforrowatinexpath:
中,我调用了一个方法,该方法调用
[self.tableView cellforrowatinexpath:indexPath]
。(正在重用现有代码,并将一些逻辑移到下游。)


结果是,
cellforrowatinexpath:
返回的单元格还不可用。您或者需要在
tableView:cellforrowatinexpath:
中修改单元格,或者,我猜,传递
*单元格

我的
cellforrowatinexpath
返回nil,原因是我在UITableView必须未完全初始化和填充的方法中调用它。一旦我将对
CellForRowatineXpath
的调用移动到
-(void)viewDidDisplay:(BOOL)animated
中,我的单元格就正确返回了。

值得一提的是,如果单元格不可见,CellForRowatineXpath:也将返回nil


当线程化时,这尤其是一个问题…

我与您的情况非常相似,但我通过调用“super”函数而不是self.tableView解决了这个问题。我不知道为什么,但至少它起作用了。也许你可以试试

[super tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

我看不出你在哪里覆盖了CellforRowatinex。只要不这样做,就不会有任何单元格。添加了更多代码。。现在看看。THX配置是什么意思?如何配置?将背面的两个操纵杆垂直移动。然后按下开始按钮,很简单。顺便说一句,我的表格是一个静态表格,它可能与您的情况不同。根据苹果公司的说法,从iOS 11开始,您必须防止使用tableView:CellForRowatineXpath:method,否则它将使您的应用程序崩溃。@VineTashTekar什么?我到处都找不到这个信息。你能出示任何证实此信息的参考资料吗?嗨@VineTashtekar,如果你能提供参考资料会更好。另外,我的答案发表在2015年,iOS 11没有发布。你能建议我的答案是否不推荐,以便我编辑它吗?你如何处理这个问题?当另一个VC激活时,我需要一个单元格的引用。你说的“另一个VC”是什么意思?另一个激活的VC(B)不会影响不同VC(a)中的细胞。这是指1VC中的单元格,并且:如果某个单元格不处于活动状态,则不会获得对该单元格的引用,因为该单元格不存在。VC回收几个单元格对象并重用它们。保留单元格的副本并在需要的地方使用它有意义吗?不,通常不需要保留对单元格对象的直接引用,单元格对象会不断重用并由表对象管理。单元格对象表示任意给定时间数据源中的不同项。如果单元格不可见,则无需对其执行任何操作,因为它不存在。通常,尝试访问看不见的单元格是错误的。谢谢,这是非常重要的信息,节省了我的时间。在BeginUpdate和EndUpdate中获取CellForRowatineXpath如何帮助确保单元格不为零?
[super tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];