- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经问过关于保存按下按钮状态的相同问题,我认为我应该以同样的方式在单元格上保存进度状态,但我的尝试没有成功。
我现在在做什么:我选择了一些 UICollectionViewCell 的
,然后按下“下载”按钮,然后开始下载操作。我选择的每个单元格都显示 UIProgressView
,一切正常,直到我向上或向下滚动 UICollectionView
。当我这样做时,另一个单元格也有进度 View ,但它们不能!我知道我必须将所选单元格的 indexPath
保存在 NSMutableArray
中,然后在 cellForItemAtIndexPath
中检查当前单元格 indexPath 是否在我的数组中,然后显示或隐藏我的单元格的 subview 。我这样做了,但它只适用于细胞选择!我应该怎么做才能在每个单元格上保存进度 View 状态,这个进度真的在那里吗?
这是我的代码:
在cellForItemAtIndexPath
中:
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)indexPath.row];
if ([selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]] )
{
cell.selectedBG.hidden = NO;
cell.selectedImg.hidden = NO;
}
else
{
cell.selectedBG.hidden = YES;
cell.selectedImg.hidden = YES;
cell.progressView.hidden = YES;
}
在didSelectItemAtIndexPath:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
...
// Add the selected item into the array
[selectedIds addObject:selectedId];
[selectedVideos addObject:selectedVideo];
AVMVideoCell *collectionCell = (AVMVideoCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)indexPath.row];
if ( ![selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]] )
{
[selecedCellsArray addObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
collectionCell.selectedBG.hidden = NO;
collectionCell.selectedImg.hidden = NO;
[collectionCell setSelected:YES];
}
}
}
在didDeselectItemAtIndexPath
中:
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
...
// Delete the selected item from the array
[selectedIds removeObject:selectedId];
[selectedVideos removeObject:selectedVideo];
AVMVideoCell *collectionCell = (AVMVideoCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)indexPath.row];
if ( [selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]] )
{
[selecedCellsArray removeObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
collectionCell.selectedBG.hidden = YES;
collectionCell.selectedImg.hidden = YES;
[collectionCell setSelected:NO];
}
}
这就是我展示进步的方式:
-(NSString *)progress:(long long )val1 : (long long )val2 : (AVMVideoCell *)cell : (NSString *)name : (NSIndexPath *)path{
float progress = ((float)val1) / val2;
NSString *prog = [[NSNumber numberWithFloat:progress*100] stringValue];
if (prog != nil){
if(cell.isSelected){
cell.selectedImg.hidden = YES;
cell.progressView.hidden = NO;
}
}
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)path.row];
if ( [selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]])
{
[cell.progressView setProgress:progress animated:YES];
}
if([prog intValue]==100){
cell.progressView.hidden = YES;
}
return prog;
}
编辑:AVMVideoCell.m
#import "AVMVideoCell.h"
@implementation AVMVideoCell
{
NSString *fullUrl;
}
@synthesize imageView;
@synthesize selectedBG;
@synthesize progressLabel;
@synthesize progressView;
@synthesize selectedImg;
@synthesize progLayer;
-(void) setVideo:(AVMDataStore *)video {
if(_video != video) {
_video = video;
}
NSString *durString = [NSString stringWithFormat:@"%@",[self timeFormatted:_video.duration]];
if((_video.filePreview != nil) && ![_video.filePreview isEqualToString:@""]){
fullUrl = [NSString stringWithFormat:@"http://example.com%@",_video.filePreview];
}
NSURL *imgURL = [NSURL URLWithString:fullUrl];
[self.imageView setImageWithURL:imgURL
placeholderImage:[UIImage imageNamed:@"yesterday.png"] options:0 usingActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.duration.text = durString;
}
- (NSString *)timeFormatted:(int)totalSeconds
{
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
}
@end
编辑 2:进度说明 我的 progressView 不是 IBOutlet
它是 @property (nonatomic,strong) UIProgressView *progressView;
(AVMVideoCell.h)
我在 cellForItemAtIndexPath
中分配并初始化它:
cell.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,0, 150.0f, 1.0f)];
cell.progressView.trackTintColor = [UIColor colorWithWhite:255 alpha:0.5f];
cell.progressView.progressTintColor = [UIColor whiteColor];
[cell.progLayer addSubview:cell.progressView];
cell.progressView.hidden = YES;
cell.progressView.tag = indexPath.row+500;
这就是我称之为进度变化显示的地方:
-(void)downloadStart:(NSString*)fileUrl : (NSString*)name : (AVMVideoCell *) cell : (NSIndexPath *)path{
NSURL *URL = [NSURL URLWithString:fileUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSString *fileName = [NSString stringWithFormat:@"%@.mp4",name]; //set full file name to save
AFHTTPRequestOperation *downloadRequest = [[AFHTTPRequestOperation alloc] initWithRequest:request]; //create download request
[downloadRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSData *data = [[NSData alloc] initWithData:responseObject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToFile = [NSString stringWithFormat:@"%@/%@", [paths firstObject],fileName]; // path to 'Documents'
NSString *pathOfFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:pathOfFile append:NO];
BOOL success = [data writeToFile:pathToFile atomically:YES];
if(success){
[self checkIfExists:name : cell :path];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"file downloading error : %@", [error localizedDescription]);
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil ];
[alert show];
cell.progressView.hidden = YES;
}];
// Step 5: begin asynchronous download
[downloadRequest start];
[downloadRequest setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
[self progress:totalBytesRead :totalBytesExpectedToRead :cell :name : path]; //here I pass val1 and val 2
}];
}
当我在 Collection View 中选择一个项目时,我收集他们模型的对象,获取每个 id 并制作 url 数组,然后在 for..in 循环中我一个接一个地传递 url,然后开始异步下载。你可以看到我如何下载和调用上面的进度方法。
最佳答案
我需要知道您是否有重用问题或模型问题。
所以首先试试这个:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
...
if (![selectedIds.containsObject:selectedId])
{
// Add the selected item into the array
[selectedIds addObject:selectedId];
[selectedVideos addObject:selectedVideo];
AVMVideoCell *collectionCell = (AVMVideoCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)indexPath.row];
if ( ![selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]] )
{
[selecedCellsArray addObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
collectionCell.selectedBG.hidden = NO;
collectionCell.selectedImg.hidden = NO;
[collectionCell setSelected:YES];
}
}
else {
// Delete the selected item from the array
[selectedIds removeObject:selectedId];
[selectedVideos removeObject:selectedVideo];
AVMVideoCell *collectionCell = (AVMVideoCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:(unsigned int)indexPath.row];
if ( [selecedCellsArray containsObject:[NSString stringWithFormat:@"%@",rowNsNum]] )
{
[selecedCellsArray removeObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
collectionCell.selectedBG.hidden = YES;
collectionCell.selectedImg.hidden = YES;
[collectionCell setSelected:NO];
}
}
并移除 didDeselect 委托(delegate)。
让我知道接下来会发生什么。
编辑:
好的,现在试试这个:
// Lazy instantiation of the progressView
- (UIProgressView *)progressView
{
if (!_progressView)
{
_progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,0, 150.0f, 1.0f)];
_progressView.trackTintColor = [UIColor colorWithWhite:255 alpha:0.5f];
_progressView.progressTintColor = [UIColor whiteColor];
_progressView.hidden = YES;
[self.contentView addSubview:_progressView];
}
return _progressView;
}
// Here we remove the progressView on reuse
-(void)prepareForReuse
{
[super prepareForReuse];
[self.progressView removeFromSuperview];
self.progressView = nil;
}
同时删除您在 cellForItemAtIndexPath 方法中对 progressView 所做的操作。
关于ios - 保存 UICollectionViewCell 进度状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604682/
堆栈:Mac OS 10.15.6,Xcode 版本 12.0 (12A7209) 我有一个自行调整大小的收集单元。我覆盖 preferredLayoutAttributesFitting获得自我调整
我有一个 Storyboard,它是在 Xcode 6 中创建的,带有 Collection View ,并且单元格具有不同的大小类变化,例如不同的字体大小......( Storyboard中创建的
我有一个 UICollectionView,只有 1 个部分,该部分中有许多单元格。我启用了拖放行为(使用长按手势识别器,因为 UICollectionView 位于通用 UIViewControll
按照我的老问题here : How to add UIView inside a UITableViewCell Programmatically? 我想通过在这些 collectionViewCel
我将 UICollectionViewCell 与父 UICollectionViewCell 中的按钮一起使用: protocol DayCellDelegate { func button
例如,我有 10 个单元格的 UICollectionView。我想为选定的单元格添加边框,稍后,在选择另一个单元格时,想要删除以前的边框并为新的选定单元格添加边框。 我怎样才能做到这一点? 我已经试
我有一个 UICollectionViewCell(比如 UICollectionViewCell 1),单元格内有一个按钮和 UITextfields。连接到 (ViewController 1)
我在单个 UICollectionViewCell 内有 (3) UITextViews、(1) UITextField 和 (1) UILabel >。当文本换行到第二行时,在符合 UITextVi
我对 TableVieCell 中的 collectionView 有疑问。当我点击 collectionCell 时,didSelectItemAt 不会被调用。我在 collectionCell
我最近在我的 Storyboard中添加了一个 UICollectionView,它当前被另一个 View 插入 View ,这似乎工作正常但是,使用 Storyboard编辑器我将 View 设置为
我想在 UICollectionViewCell 上开始一些动画当用户点击一个单元格时。我的想法是在 didSelectItemAtIndexPath 中选择相应的单元格并触发动画。但是,这不起作用:
我可以通过使用手势识别器拖动它并简化新的 iOS 9 对重新排序的支持来重新排序 iOS 9 上的 UICollectionViewCells。 public func beginInteractiv
我正在开发一个应用程序,其中我在 UICollectionView 中实现了编辑模式。我正在尝试实现如下所示的内容: 当我单击编辑按钮时,相机按钮和眼睛按钮应隐藏,删除和重命名按钮应如下所示: 编辑后
我希望所有单元格之间以及屏幕边框和最近的单元格之间的间距相等。基本上是这样的。内部和周围的间距相等。 我设法通过设置这样的值在界面生成器中测试这一点。我将单元格大小设置为 110,最小间距设置为 0,
我已经设置了一个 UICollectionView,如下所示。我正在尝试设置自定义单元格高度,以便该集合在必须滚动之前适合屏幕上的 3 个单元格。但是,这种定制工作不起作用或似乎被忽略了。有谁知道我做
我在不使用 Storyboard的情况下以编程方式创建了 UICollectionView 和 UICollectionViewCell,但是发生了一些事情,我无法理解为什么。 BKPhotoCell
我正在寻找制作图片库。我希望我的图像全屏显示,但不确定这如何与自动布局一起使用。我知道有一种方法可以返回单元格的大小,但不知道我是否应该只获取屏幕大小并返回它,或者是否有使用自动布局的方法。 最佳答案
我有一个问题, 我有一个简单的 UICollectionView,其中包含从 Flickr 加载图像的静态 200 个单元格。 我的 CellForItemAtIndexPath 看起来像这样: -
以下代码是一个非常简单的程序,用于在 UICollectionView 中显示 1-10000 之间的数字。 .它在不滚动的情况下正确显示,但是如果您向下滚动并向后滚动 Collection View
这个问题在这里已经有了答案: UICollectionViewLayout Not working with UIImage in Swift 5 and Xcode 11 (2 个答案) 关闭 2
我是一名优秀的程序员,十分优秀!