- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个问题,当我单击一个单元格时,什么也没有发生,当我单击第二个单元格时,它会在简历中显示前一个单元格(或我第一个单击的单元格)的数据,我认为它显示了错误的索引.item(在详细 View 中)
#define API_V3_CHANNEL_URL @"examples.json"
@interface MSContestListViewController ()
@end
@implementation MSContestListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
NSArray *colors = [[NSArray alloc] initWithObjects:
[UIColor colorWithRed:1 green:0.529 blue:0.357 alpha:1.0],
[UIColor colorWithRed:1 green:0.439 blue:0.357 alpha:1.0],
[UIColor colorWithRed:0.937 green:0.302 blue:0.357 alpha:1.0],
[UIColor colorWithRed:0.737 green:0.212 blue:0.357 alpha:1.0],
nil];
CAGradientLayer *gradient = [DREasyGradient gradientWithFrame:frame
orientation:DRHorizontalGradient
colors:colors];
[self.view.layer insertSublayer:gradient atIndex:0];
_segmentedControl.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
[self fetchEntries];
[self fetchEntriesWinner];
[self fetchEntriesPhotos];
}
- (void)fetchEntries
{
NSString *searchURL = [API_V3_CHANNEL_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *searchData = [NSData dataWithContentsOfURL:[NSURL URLWithString:searchURL]];
NSDictionary *searchDict =[NSJSONSerialization JSONObjectWithData:searchData options:NSJSONReadingMutableContainers error:nil];
//self.readArray = [searchDict objectForKey:@"CONTESTS"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status == %@", @"LIVE"];
self.readArray = [[searchDict objectForKey:@"CONTESTS"] filteredArrayUsingPredicate:predicate];
NSLog(@"%@", self.readArray);
}
- (void)fetchEntriesWinner
{
NSString *searchURL = [API_V3_CHANNEL_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *searchData = [NSData dataWithContentsOfURL:[NSURL URLWithString:searchURL]];
NSDictionary *searchDict =[NSJSONSerialization JSONObjectWithData:searchData options:NSJSONReadingMutableContainers error:nil];
//self.readArray = [searchDict objectForKey:@"CONTESTS"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status == %@", @"ARCHIVED"];
self.readArrayWinner = [[searchDict objectForKey:@"CONTESTS"] filteredArrayUsingPredicate:predicate];
NSLog(@"winner array : %@", self.readArrayWinner);
}
- (void)fetchEntriesPhotos
{
NSString *searchURL = [API_V3_CHANNEL_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *searchData = [NSData dataWithContentsOfURL:[NSURL URLWithString:searchURL]];
NSDictionary *searchDict =[NSJSONSerialization JSONObjectWithData:searchData options:NSJSONReadingMutableContainers error:nil];
//self.readArray = [searchDict objectForKey:@"CONTESTS"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status == %@", @"LIVE"];
self.readArrayPhotos = [[searchDict objectForKey:@"CONTESTS"] filteredArrayUsingPredicate:predicate];
NSLog(@"%@", self.readArray);
}
- (IBAction)segmentedControlAction:(id)sender
{
switch(_segmentedControl.selectedSegmentIndex)
{
case 0:
if(self.readArray.count == 0)
{
[self fetchEntries];
} else {
[self.collectionView reloadData];
}
break;
case 1:
if(self.readArrayWinner.count == 0)
{
[self fetchEntriesWinner];
} else {
[self.collectionView reloadData];
}
break;
case 2:
if(self.readArrayPhotos.count == 0)
{
[self fetchEntriesPhotos];
} else {
[self.collectionView reloadData];
}
break;
default:
break;
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
switch (_segmentedControl.selectedSegmentIndex) {
case 0:
return [self.readArray count];
break;
case 1:
return [self.readArrayWinner count];
break;
case 2:
return [self.readArrayPhotos count];
break;
default:
break;
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"pictureCell";
MSContestListCollectionViewCell *cell = (MSContestListCollectionViewCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.titleContest.adjustsFontSizeToFitWidth = YES;
cell.titleContest.minimumScaleFactor = 0.5;
cell.pictureImageView.layer.cornerRadius = 5;
cell.pictureImageView.clipsToBounds = YES;
cell.titleView.layer.cornerRadius = 5;
cell.titleView.clipsToBounds = YES;
switch (_segmentedControl.selectedSegmentIndex) {
case 0: {
NSDictionary *searchResult = [self.readArray objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult objectForKey:@"featuredImage"];
NSString *image = [NSString stringWithFormat:@"https://srv.mediaswapp.com/%@", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.titleContest.text = [searchResult objectForKey:@"description"];
cell.statusContest.text = [searchResult objectForKey:@"status"];
break;
}
case 1: {
NSDictionary *searchResult2 = [self.readArrayWinner objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult2 objectForKey:@"featuredImage"];
NSString *image = [NSString stringWithFormat:@"https://srv.mediaswapp.com/%@", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.titleContest.text = [searchResult2 objectForKey:@"description"];
cell.statusContest.text = [searchResult2 objectForKey:@"status"];
break;
}
case 2: {
NSDictionary *searchResult3 = [self.readArrayPhotos objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult3 objectForKey:@"featuredImage"];
NSString *image = [NSString stringWithFormat:@"https://srv.mediaswapp.com/%@", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.titleContest.text = [searchResult3 objectForKey:@"description"];
cell.statusContest.text = [searchResult3 objectForKey:@"status"];
break;
}
default:
break;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *searchResult = [self.readArray objectAtIndex:indexPath.item];
NSString *videoID = [searchResult objectForKey:@"description"];
NSString *stringImage = [searchResult objectForKey:@"featuredImage"];
NSString *image = [NSString stringWithFormat:@"https://srv.mediaswapp.com/%@", stringImage];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
MSContestDetailViewController *yourController = (MSContestDetailViewController *)[mainStoryboard
instantiateViewControllerWithIdentifier:@"contestDetailViewController"];
yourController.urlImage = image;
yourController.contestName = videoID;
yourController.contestTime = [searchResult objectForKey:@"drawDate"];
[self.navigationController pushViewController:yourController animated:YES];
}
@end
最佳答案
您应该使用 didSelectItemAtIndexPath
函数而不是 didDeselectItemAtIndexPath
:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *searchResult = [self.readArray objectAtIndex:indexPath.item];
NSString *videoID = [searchResult objectForKey:@"description"];
NSString *stringImage = [searchResult objectForKey:@"featuredImage"];
NSString *image = [NSString stringWithFormat:@"https://srv.mediaswapp.com/%@", stringImage];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
MSContestDetailViewController *yourController = (MSContestDetailViewController *)[mainStoryboard
instantiateViewControllerWithIdentifier:@"contestDetailViewController"];
yourController.urlImage = image;
yourController.contestName = videoID;
yourController.contestTime = [searchResult objectForKey:@"drawDate"];
[self.navigationController pushViewController:yourController animated:YES];
}
关于ios - 单击 CollectionViewCell 显示先前选择的单元格而不是当前单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34949499/
我有一个自定义 TagCollectionViewCell,它是一个自定义 UICollectionViewCell。在 .xib 时代,我曾经通过 UINib 实例化,但现在使用 Storyboar
不幸的是,我继续遇到约束问题......我绝对是我的问题,但我真的无法理解它们...... 我创建了一个带有自定义单元格的 UICollectionView。 在单元格内,我插入了一个带有所有约束的
在我的应用程序中,我将使用 Collection View ,但我遇到了问题。我在 Storyboard中设计了 Collection View 。我在 View Controller 中插入了一个
我正在使用连接到 CVCell 的 CollectionView 和捏合手势。我在单元格中有一张图像,并且捏合手势放大和缩小图像。我的问题是捏合手势仅适用于偶数行,不适用于奇数行。我的意思是,对于第一
我想隐藏被点击的单元格中的标签,而是显示图像。但我只想在具有特定索引的单元格已设置为 imageView 时才执行此操作。如果单元格设置为 imageView 或不设置,寻址单元格和存储的最佳方式是什
我希望每个 CollectionViewCell 显示图像并在点击时隐藏标签。但是,如果用户滚动图像,则会突然在其他未触摸过的过程中显示。如何识别某些细胞? override func collect
我正在尝试创建一个activityCell,因此当用户到达按钮时,它将显示一个带有事件指示器的单元格。这似乎工作正常,但是如果 moreDataAvailable 为 false 它应该删除此单元格。
我在 CollectionViewCell 中有 2 个标签和 1 个 ImageView 。我可以在单元格中设置图像,但无法在单元格中设置标签。 CollectionViewCell 类: clas
我正在制作一个程序,单个 View Controller 有两个 Collection View 。我已成功填充顶 View Controller ,但在添加第二个 Controller 时,我无法正
我水平滚动 CollectionView 单元格数量未知,它占据了除导航栏之外的整个屏幕。还有 CollectionViewCell,它占用整个 CollectionView。另外,在这个单元格内,我
我有一个布局,它使用多个collectionviewcells来布局。目前我使用的是静态高度,但众所周知,无法确定内容的大小,特别是在我的情况下,因为它将是占据单元格大部分的文本。我无法找到一种准确的
我正在发送从 collectionView 中选择的图像。问题是应用程序总是发送先前选择的图像。 indexPath 有什么问题? 这是 didSelectItemAt 函数: override fu
到目前为止,我一直在成功使用 UITableViews,但我无法让 UICollectionView 工作。 @interface NewsCollectionViewDataSource : NSO
我正在尝试在我的 Collection View 单元格内绘制一个简单的轮廓圆圈。由于某种原因,只有第一个单元格被绘制,其余的没有显示。 class UserCell: UICollectionVie
我使用 Xib 文件创建了一个 Collection View 单元格。我只有一个单元格,但该单元格显示在 collectionView 的中心。我想在 collectionView 的起始位置显示单
我有一个非常简洁的动画,它基本上为 Collection View 单元格绘制了一个边框。 我的动画运行良好,但我无法阻止它无限期地重复。 在:func collectionView(collecti
我一直在寻找学习这个 link 中的 Collection View 一天。在此链接中,它有 viewcontroller.h,.m 和 CustomCollectionCell.h,.m。 他们为什
我有 3 个单元格的 Collection View 。我在它们上面显示图像,但是,因为从服务器获取图像数据需要几秒钟,所以我使用 nsuserdefaults 和缓存。 let imagesFrom
我在使用 uicollectionview 时遇到问题。当我做一个collectionviewcell,在collectionviewcell里做一个uilabel的时候,突然uilabel不见了。
我已经为我的 UICollectionViewCell 设置了一个 UIPanGestureRecognizer,它应该像您经常在 UITableViewCells 中看到的那样工作,显示内容下方的控
我是一名优秀的程序员,十分优秀!