简体   繁体   English

tableview单元无法正确更新

[英]tableview cells not updating properly

I am using table view to show downloaded songs.I am creating empty folder before downloading song without extinction ".mp3" after downloading song I am replacing that file with original file which has extinction of .mp3 .now aim getting files on music folder and shooing it in table view. 我正在使用表格视图显示下载的歌曲。我在下载歌曲之前创建了一个空文件夹,下载的歌曲之后没有熄灭的“ .mp3”。我将文件替换为已经熄灭的.mp3的原始文件。现在的目标是在音乐文件夹和在表格视图中射击。 The table view shows activity indicator in cell before downloading song. 表格视图在下载歌曲之前在单元格中显示活动指示器。 After downloading song i replace the activity indicator by a button by hiding it. 下载歌曲后,我将隐藏的活动指示器替换为一个按钮。 My problem is after downloading the file it was not able to replace the button but it hid the indicator. 我的问题是下载文件后,它无法替换按钮,但隐藏了指示器。 even though i scrolled the button doesn't appear. 即使我滚动按钮也没有出现。 Whenever i close that view controller and return back to download list it shows properly. 每当我关闭该视图控制器并返回到下载列表时,它就会正确显示。 after downloading file i tried [tableview reload data]; 下载文件后,我尝试了[tableview reload data]; but no change. 但没有变化。

any help would be appreciated iam usingI am using table view to show downloaded songs. 我将使用表格视图来显示下载的歌曲。 The table view shows activity indicator in cell before downloading song. 表格视图在下载歌曲之前在单元格中显示活动指示器。 After downloading song i replace the activity indicator by a button by hiding it. 下载歌曲后,我将隐藏的活动指示器替换为一个按钮。 My problem is after downloading the file it was not able to replace the button but it hid the indicator. 我的问题是下载文件后,它无法替换按钮,但隐藏了指示器。 even though i scrolled the button doesn't appear. 即使我滚动按钮也没有出现。 Whenever i close that view controller and return back to download list it shows properly. 每当我关闭该视图控制器并返回到下载列表时,它就会正确显示。 after downloading file i tried [tableview reload data]; 下载文件后,我尝试了[tableview reload data]; but no change. 但没有变化。

any help would be appreciated 任何帮助,将不胜感激

                             if((![[songName substringFromIndex:MAX((int)            [songName length]-4, 0)] isEqualToString:@".mp3"])    
       {        
CoustoumCell *cellMain = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];           
    cellMain.backgroundView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Table-view-background.png"]];           
 cellMain.AlbumLable.textColor = [UIColor colorWithRed:0.278 green:0.278  blue:0.278 alpha:1.0];
cellMain.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Table-view-selected-background.png"]];
cellMain.indiCatorForDon.tag=indexPath.row;
[cellMain.indiCatorForDon startAnimating];
[cellMain.playButton removeFromSuperview];

cellMain.imageView.image=Nil;
cellMain.downloadStatusLable.text=@"Downloading....";
cellMain.AlbumLable.text=[_songsList objectAtIndex:indexPath.row];
cellMain.numberLable.text=[NSString stringWithFormat:@"%d",indexPath.row+1];
}
   else
{
CoustoumCell *cellMain = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cellMain.backgroundView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Table-view-background.png"]];
cellMain.AlbumLable.textColor = [UIColor colorWithRed:0.278 green:0.278    blue:0.278 alpha:1.0];
cellMain.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Table-view-selected-background.png"]];
cellMain.AlbumLable.text=[_songsList objectAtIndex:indexPath.row];
    [cellMain.indiCatorForDon stopAnimating];
cellMain.downloadStatusLable.textColor = [UIColor colorWithRed:0.278 green:0.278 blue:0.278 alpha:1.0];
cellMain.sizeLable.textColor = [UIColor colorWithRed:0.278 green:0.278 blue:0.278 alpha:1.0];
cellMain.sizeLable.text=[[self getSize] objectAtIndex:indexPath.row];
cellMain.downloadStatusLable.text=@"Downloaded";
cellMain.completedImage.image=[UIImage imageNamed:@"checked.png"];
    cellMain.numberLable.text=[NSString stringWithFormat:@"%d",indexPath.row+1];
cellMain.playButton.tag=indexPath.row;
}
    return cellMain;

after downloading song sending notification from another view to table view 下载歌曲后,将通知从另一个视图发送到表格视图

  - (void) receiveTestNotification:(NSNotification *) notification
{
   if ([[notification name] isEqualToString:@"TestNotification"])
         {
           NSLog (@"Successfully received the test notification!");

    // Perform long running process
       [self  updateDownloadList];
       [[AlbumsAnsSongs sharedManager] getallFiles];
       [_tableView reloadData];
   }
 }

Since problem is with UI update so I guess when your data completes downloading you should call reloadData method like this: 由于问题在于用户界面更新,因此我猜您的数据下载完成后,应调用reloadData方法,如下所示:

 - (void) receiveTestNotification:(NSNotification *) notification
{
   if ([[notification name] isEqualToString:@"TestNotification"])
         {
           NSLog (@"Successfully received the test notification!");

    // Perform long running process
       [self  updateDownloadList];
       [[AlbumsAnsSongs sharedManager] getallFiles];

       dispatch_async(dispatch_get_main_queue(), ^(void){
            [_tableView reloadData];
        });

   }
 }

Another problem that seems to be there is that you are removing the button with this statement 似乎存在的另一个问题是您正在使用此语句删除按钮

[cellMain.playButton removeFromSuperview];

but in else part you are not adding the button back, 但在其他部分,您并没有添加按钮,

I think instead of removing playButton you should hide the button 我认为应该删除按钮而不是删除playButton

cellMain.playButton.hidden = YES

and then in else part 然后在其他部分

cellMain.playButton.hidden = NO

Explanation: 说明:

You were removing the button from cell, since the cells are dequed or you can say reused , cells without button were being displayed on the screen 您正在从单元格中删除按钮,因为单元格已经过时,或者您可以说是reuse,所以没有按钮的单元格正在屏幕上显示

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

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