1

非表示のスピナーと非表示のテキスト「もっと読み込む」を含むカスタム セルを作成しました。これらのフィールドは、ユーザーがクリックしてさらにデータを要求できるように、最後のセルに対して非表示にされていません。ユーザーが最後のセルをクリックするとスピナーが開始するようにしていますが、ユーザーがセルをスクロールしてビューから外し、再びスピナーが表示されないようにします。どんな助けでも大歓迎です.:)

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の中に:

- (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 私は持っています:

 - (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];
    }
  }
}
4

4 に答える 4

1

cellForRowAtIndexPath に以下を追加しました。

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

reloadTableViewData に以下を追加しました。

spinnerIsOn=NO;

didSelectRowAtIndexPath に以下を追加しました。

spinnerIsOn = TRUE;
于 2013-04-11T07:00:08.307 に答える
0

layoutSubviews をサブクラス化することもできます

- (void)layoutSubviews{
    [super layoutSubviews];
    [self.spinner startAnimating];
}
于 2015-01-13T15:24:18.577 に答える