繁体   English   中英

UIActivityIndi​​catorView不对UITableViewCell进行动画处理?

[英]UIActivityIndicatorView not animating on UITableViewCell ?

我有UITableView,我正在从服务器填充数据。 我实现了某种分页,因此我转到服务器并获取7个项目,然后向下滚动时获取另外7个,依此类推。 这工作得很好,但是我想在最后一个单元格上添加UIActivityIndi​​catorView,以便用户看到尚未下载所有数据。 我的问题是UIActivityIndi​​catorView没有旋转。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     if (self.needPagin)
         return allData.count+1;
     return allData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  UIActivityIndicatorView * indicator = nil;
  NSString *CellIdentifier = @"ResultCell";
  cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  .....
  if (allData.count> indexPath.row) {
      [indicator stopAnimating];
      indicator.hidden = YES;
  }
  else{
      indicator.hidden = NO;
      [indicator startAnimating];
  }
  return cell;
}

UIActivityIndi​​catorView正确显示,但没有旋转。 谁能帮我解决问题?

编辑:

完整的代码是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setBackgroundView:nil];
tableView.backgroundColor = [UIColor clearColor];
tableView.separatorColor = [Color separatorColor];

UITableViewCell *cell;

UILabel * titleLable = nil;
UILabel * addressLable = nil;
UILabel * emailLable = nil;
UILabel * phoneLable = nil;
UIImageView * icon = nil;
UIImageView * star = nil;
UIImageView * icon1 = nil;
UIImageView * icon2 = nil;
UIActivityIndicatorView * indicator = nil;

NSString *CellIdentifier = @"ResultCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"ResultCell" owner:self options:nil];
    cell = self.resultCell;
    self.resultCell = nil;

    if (!star)
        star = (UIImageView*)[cell viewWithTag:5];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addToFavorites:)];
    [star addGestureRecognizer:tap];
    star.userInteractionEnabled = YES;


    titleLable = (UILabel*)[cell viewWithTag:1];
    addressLable = (UILabel*)[cell viewWithTag:2];
    emailLable = (UILabel*)[cell viewWithTag:3];
    phoneLable = (UILabel*)[cell viewWithTag:6];
    icon = (UIImageView*)[cell viewWithTag:4];
    star = (UIImageView*)[cell viewWithTag:5];
    indicator = (UIActivityIndicatorView*)[cell viewWithTag:9];

    [titleLable setFont:[UIFont fontWithName:[Fonts mainFontName] size:13]];
    [titleLable setTextColor:[Color cellButtonColor]];

    [addressLable setFont:[UIFont fontWithName:[Fonts mainFontName] size:12]];
    [addressLable setTextColor:[Color cellButtonColor]];

    [emailLable setFont:[UIFont fontWithName:[Fonts mainFontName] size:10]];
    [emailLable setTextColor:[Color secondButtonColor]];
    [emailLable setAdjustsFontSizeToFitWidth:YES];

    [phoneLable setFont:[UIFont fontWithName:[Fonts mainFontName] size:10]];
    [phoneLable setTextColor:[Color secondButtonColor]];
    [phoneLable setAdjustsFontSizeToFitWidth:YES];

    [indicator setColor:[Color mainButtonColor]];
}

if (!titleLable)
    titleLable = (UILabel*)[cell viewWithTag:1];
if (!addressLable)
    addressLable = (UILabel*)[cell viewWithTag:2];
if (!emailLable)
    emailLable = (UILabel*)[cell viewWithTag:3];
if (!icon)
    icon = (UIImageView*)[cell viewWithTag:4];
if (!star)
    star = (UIImageView*)[cell viewWithTag:5];
if (!phoneLable)
    phoneLable = (UILabel*)[cell viewWithTag:6];
if (!icon1)
    icon1 = (UIImageView*)[cell viewWithTag:7];
if (!icon2)
    icon2 = (UIImageView*)[cell viewWithTag:8];
if (!indicator)
    indicator = (UIActivityIndicatorView*)[cell viewWithTag:9];

int sportID = -1;
FacilitiesObject * fac;
OrganisationObject * org;
RutesObject *rut;
EventsObject * eve;
id obj_;
if (allData.count> indexPath.row) {

    titleLable.hidden = NO;
    addressLable.hidden = NO;
    emailLable.hidden = NO;
    icon.hidden = NO;
    star.hidden = NO;
    phoneLable.hidden = NO;
    icon1.hidden = NO;
    icon2.hidden = NO;
    [indicator stopAnimating];
    indicator.hidden = YES;

    switch (self.state) {
        case _sportObject_:
            fac = [allData objectAtIndex:indexPath.row];
            [titleLable setText:fac.name];
            [addressLable setText:fac.address];
            [emailLable setText:fac.email];
            [phoneLable setText:fac.tel];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (fac.sports.count>0) {
                sportID = [[fac.sports objectAtIndex:0]intValue];
            }
            if (fac.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];

            obj_ = fac;
            break;
        case _sportOrg_:
            org= [allData objectAtIndex:indexPath.row];
            [titleLable setText:org.name];
            [addressLable setText:org.address];
            [emailLable setText:org.email];
            [phoneLable setText:org.tel];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (org.sports.count>0) {
                sportID = [[org.sports objectAtIndex:0]intValue];
            }
            if (org.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];
            obj_ = org;
            break;
        case _gpsRoots_:
            rut = [allData objectAtIndex:indexPath.row];
            [titleLable setText:rut.name];
            [addressLable setText:[NSString stringWithFormat:@"Dolžina : %i", rut.langth]];
            [emailLable setText:[NSString stringWithFormat:@"%i", rut.altitude]];
            [phoneLable setText:[NSString stringWithFormat:@"%i", rut.duration]];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (rut.sports.count>0) {
                sportID = [[rut.sports objectAtIndex:0]intValue];
            }
            if (rut.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];
            break;
        case _eventEvent_:
            eve = [allData objectAtIndex:indexPath.row];
            [titleLable setText:eve.name];
            [addressLable setText:eve.address];
            [emailLable setText:eve.email];
            [phoneLable setText:eve.tel];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (eve.sports.count>0) {
                sportID = [[eve.sports objectAtIndex:0]intValue];
            }
            if (eve.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];
            obj_ = eve;
            break;
        case _exercice_:
            eve = [allData objectAtIndex:indexPath.row];
            [titleLable setText:eve.name];
            [addressLable setText:eve.address];
            [emailLable setText:eve.email];
            [phoneLable setText:eve.tel];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (eve.sports.count>0) {
                sportID = [[eve.sports objectAtIndex:0]intValue];
            }
            if (eve.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];
            obj_ = eve;
            break;
        case _competition_:
            eve = [allData objectAtIndex:indexPath.row];
            [titleLable setText:eve.name];
            [addressLable setText:eve.address];
            [emailLable setText:eve.email];
            [phoneLable setText:eve.tel];
            if (self.filter.sport) {
                sportID = self.filter.sport.picture;
            }
            else if (eve.sports.count>0) {
                sportID = [[eve.sports objectAtIndex:0]intValue];
            }
            if (eve.favourites)
                [star setImage:[UIImage imageNamed:@"favourite_on"]];
            else
                [star setImage:[UIImage imageNamed:@"favourite_off"]];
            obj_ = eve;
            break;
        default:
            break;
    }

    [icon setImage:[UIImage imageNamed:[SportsObject sportImageName:sportID]]];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;

}
else{
    titleLable.hidden = YES;
    addressLable.hidden = YES;
    emailLable.hidden = YES;
    icon.hidden = YES;
    star.hidden = YES;
    phoneLable.hidden = YES;
    icon1.hidden = YES;
    icon2.hidden = YES;
    indicator.hidden = NO;
    [indicator startAnimating];
}

// 

// load next page
if(indexPath.row == allData.count-4 && self.needPagin)
    [self nextPage];

return cell;

}

所有的用户界面都在XIB中制作。

您正在制作零动画。 您必须实例化微调器,然后将其添加为单元格视图的子视图。

UIActivityIndicator *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

[cell.view addSubview:indicator];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM