ios:滚动后自定义单元格中的微调器消失 [英] ios:Spinner in custom cell disappears after scrolling

查看:18
本文介绍了ios:滚动后自定义单元格中的微调器消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有隐藏微调器和隐藏文本加载更多"的自定义单元格.这些字段对于最后一个单元格是未隐藏的,以便用户可以单击它以请求更多数据.我让它开始工作,以便当用户单击最后一个单元格时微调器启动,但是当用户将单元格滚动到视图之外并再次返回时,微调器不会显示.任何帮助将不胜感激.:)

I created a custom cell with a hidden spinner and hidden text "Load More". These fields are unhidden for the last cell so that the user can click it to request more data. I have it woking so that when the user clicks the last cell the spinner starts, but when the user scrolls the cell out of view and back again the spinner is not shown. Any help will be appreciated.:)

我有一个自定义单元格,它是 UITableViewCell 的子类:

I have a custom cell that is a subclass of UITableViewCell:

@interface BrowseListCell : UITableViewCell{
IBOutlet UIImageView *image;
IBOutlet UILabel *name;
IBOutlet UILabel *loadMore;
IBOutlet UIActivityIndicatorView *spinner;
}
@property(nonatomic, retain) UIImageView *image;
@property(nonatomic, retain) UILabel *name;
@property(nonatomic, retain) UILabel *loadMore;
@property(nonatomic, retain) UIActivityIndicatorView *spinner;
@end

在 tableViewController 里面我有:

Inside the tableViewController I have:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_dataController countOfList]+1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{

// Configure the cell...
static NSString *CellIdentifier = @"BrowseListCell";

BrowseListCell *cell = (BrowseListCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
    cell = [_cell autorelease];
    _cell = nil;
}
if(indexPath.row==[_dataController countOfList]){
    if (indexPath.row==0) {
        cell.name.text=nil;
        cell.image.image = nil;
        cell.loadMore.hidden = YES;
        return cell;
    }else{
        cell.name.text=nil;
        cell.image.image = nil;
        cell.loadMore.hidden = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        _spinner = [cell.spinner retain];
        _loadCell = [cell retain];
        return cell;
    }
}
if(_dataController!=nil){
    BrowseProduct *productAtIndex = [_dataController objectInListAtIndex:indexPath.row];

    // Configure the cell...
    if(productAtIndex!=nil){
        cell.name.text = productAtIndex.name;
        cell.image.image = productAtIndex.image;
        cell.loadMore.hidden=YES;
    }

}

return cell;

}

在 didSelectRowAtIndexPath 里面我有:

Inside didSelectRowAtIndexPath I have :

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==[_dataController countOfList]){
    if (indexPath.row==0) {
        //do nothing
    }else{
        NSLog(@"Loading");
        [_spinner startAnimating];
        _loadCell.userInteractionEnabled = NO;
        NSString *startFromId = [NSString stringWithFormat:@"%d", [_dataController countOfList]];
        NSNotification *notification = [NSNotification notificationWithName:@"loadMore" object:startFromId];
        [[NSNotificationCenter defaultCenter]postNotification:notification];
    }
  }
}

推荐答案

为 cellForRowAtIndexPath 添加了以下内容:

Added the following for cellForRowAtIndexPath:

if(spinnerIsOn){
            [_spinner startAnimating];
        }else{
            [_spinner stopAnimating];
        }

为 reloadTableViewData 添加了以下内容:

Added following to reloadTableViewData:

spinnerIsOn=NO;

在 didSelectRowAtIndexPath 中添加了以下内容:

Added the following to didSelectRowAtIndexPath:

spinnerIsOn = TRUE;

这篇关于ios:滚动后自定义单元格中的微调器消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆