我正在尝试向现有的单元格中添加更多单元UICollectionView格.
我试图使用CollectionView,reloadData但它似乎重新加载整个collectionView,我只是想添加更多的单元格.
有谁能够帮我?
我有一个UICollectionView将图片作为其数据存储区中的元素.
我想将高分辨率pic加载到元素中,只有当它的对应UICollectionViewCell当前显示在屏幕上时.之后,当UICollectionViewCell屏幕关闭时,我想将元素返回UIImage到低分辨率版本.
我的问题是,如何检测UICollectionViewCell屏幕何时关闭?
(我尝试使用该prepareForReuse方法,但我无法预测何时会被调用).
我目前正在使用一段代码,scrollViewDidScroll每次视图滚动时我都会检查self.collectionView.visibleCells以查看哪些单元格已在屏幕上滚动.
这看起来有点开销,我想知道UICollectionViewCell在滚动屏幕的时候是否有自己调用的方法?
ios uicollectionview uicollectionviewcell uicollectionreusableview
我正在使用UICollectionView,我正在显示手机照片库中的所有图像.
当我点击任何图像时,图像会被翻转,并显示有关图像的一些信息.
当用户再次点击同一图像时,图像再次翻转并显示原始图像.
问题是每当我向下滚动UICollectionView时,最后选择的图像会自动翻转,并显示有关图像的信息.
如何阻止这个问题.
这是一些代码:
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell1 = [collectionView cellForItemAtIndexPath:indexPath];
if(old_path!=NULL){
UICollectionViewCell *cell2 = [collectionView cellForItemAtIndexPath:old_path];
[UIView transitionFromView:cell2.selectedBackgroundView toView:cell2.contentView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
}
if(old_path==indexPath&&flag)
{
[cell1 setSelected:NO];
[UIView transitionFromView:cell1.selectedBackgroundView toView:cell1.contentView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
flag=FALSE;
}
else{
[UIView transitionFromView:cell1.contentView toView:cell1.selectedBackgroundView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
flag=TRUE;
}
old_path=indexPath;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
ALAsset *asset = assets[indexPath.row];
NSLog(@"Description : %@",[asset description]);
UIImage *img=[self imageWithImage:[UIImage imageWithCGImage:[asset …Run Code Online (Sandbox Code Playgroud) 我正在尝试做一个Collection View有人选择a cell和每个选择它将它们带到另一个View Controller包含选择内容的人.但是,当我应用这行代码时,我遇到了困难didSelectItemAtIndexPath;
self.performSegueWithIdentifer("showDetail", sender: self)
Run Code Online (Sandbox Code Playgroud)
然后在模拟器中运行它,cell选择工作正在按照indexPath它记住每次选择新选项时的选择cell.因此,例如,每个cell有照片和标签,如果我选择第一个cell在indexPath该segue第一空白视图,然后带我我的选择cell.如果我选择另一个cell,indexPath空白视图上的数字3 现在是cell我之前选择的第一个,之后我选择的第三个cell.它每次都这样做.如果我删除performSegueWithIdentifer代码(从Xcode 6.2(在6.1.1中它是随机的))选择是我以前的选择,而不是我的'selectedCell',但至少它只选择一次而不是两次来到a view.这有什么不对劲indexPath.这是我的代码prepareForSegue
override func prepareForSegue(segue: UIStoryBoardSegue, sender: AnyObject?) {
if segue.identifer == "showDetail" {
let detailVC:DetailViewController = segue.destinationViewController as DetailViewController
detailVC.selectedImageName = selectedImage
detailVC.selectedLabel = selectedLabels
}
}
Run Code Online (Sandbox Code Playgroud)
我坚持要做什么以及应用什么解决方案.我是否保留performSegueWithIdentifer代码并创建一个Equatable实现find(array, …
didselectrowatindexpath uicollectionview uicollectionviewcell swift
如何在UICollectionView使用自定义的单元格中添加边框UICollectionViewFlowLayout?当我覆盖UICollectionView的流布局时,单元格边框被"删除".如何正确设置边框?谢谢!
ios uicollectionview uicollectionviewcell uicollectionviewlayout swift
我有一个CollectionView向用户显示图像.我在后台下载这些,当下载完成后,我调用以下func来更新collectionViewCell并显示图像.
func handlePhotoDownloadCompletion(notification : NSNotification) {
let userInfo:Dictionary<String,String!> = notification.userInfo as! Dictionary<String,String!>
let id = userInfo["id"]
let index = users_cities.indexOf({$0.id == id})
if index != nil {
let indexPath = NSIndexPath(forRow: index!, inSection: 0)
let cell = followedCollectionView.cellForItemAtIndexPath(indexPath) as! FeaturedCitiesCollectionViewCell
if (users_cities[index!].image != nil) {
cell.backgroundImageView.image = users_cities[index!].image!
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果单元格当前在屏幕上可见,则此方法很有效,但如果不是
fatal error: unexpectedly found nil while unwrapping an Optional value,则在以下行中出现错误:
let cell = followedCollectionView.cellForItemAtIndexPath(indexPath) as! FeaturedCitiesCollectionViewCell
Run Code Online (Sandbox Code Playgroud)
现在,如果collectionViewCell尚未可见,则甚至不需要调用此函数,因为在这种情况下,cellForItemAtIndexPath无论如何都将在方法中设置图像.
因此我的问题是,如何更改此函数以检查我们正在处理的单元格当前是否可见.我知道collectionView.visibleCells()但是,我不知道如何在这里应用它.
我正在开发一个iOS应用程序,它将服务器中的帖子加载到UICollectionView中.集合视图单元格包含一个固定在单元格底部的UIImageView.
每当我启动应用程序并加载集合视图时,所有图像都无法正确加载,而是最后一个图像,这是正确的尺寸.所有单元格的格式都相同.
我尝试了很多解决方案,但到目前为止还没有任何效果.
我怀疑发生的是图像在设置到每个单元格的UIImageView之前没有完成加载(在这种情况下除了最后一个).虽然在获得成功响应后重新加载单元格,但这似乎不可能.
这是我特定功能的代码(使用Alamofire)
func getAllPosts(){
let url = "\(Constants.baseURL)/posts/"
let parameters = ["user_id": "\(userProfile!.getId())"]
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON)
.validate(contentType: ["application/json"])
.responseString { response in
switch response.result {
case .Success:
var postsArray = Array<[String: AnyObject]>()
do {
let json = try NSJSONSerialization.JSONObjectWithData(response.data!, options: NSJSONReadingOptions.MutableContainers)
for post in json as! [AnyObject] {
postsArray.append(post as! [String: AnyObject])
}
//invert array of posts so that latest load first!
postsArray = postsArray.reverse()
} catch {
}
//convert json to Post objects …Run Code Online (Sandbox Code Playgroud) 我想在集合视图中重新排序每个单元格的自定义大小的单元格.
在Collection View的每个单元格中都有一个带有单词的标签.
我用这段代码设置每个单元格的维度:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let word = textArray[indexPath.row]
let font = UIFont.systemFont(ofSize: 17)
let fontAttributes = [NSFontAttributeName: font]
var size = (word as NSString).size(attributes: fontAttributes)
size.width = size.width + 2
return size
}
Run Code Online (Sandbox Code Playgroud)
我使用以下代码重新排序集合视图:
override func viewDidLoad() {
super.viewDidLoad()
self.installsStandardGestureForInteractiveMovement = false
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(gesture:)))
self.collectionView?.addGestureRecognizer(panGesture)
}
func handlePanGesture(gesture: UIPanGestureRecognizer) {
switch gesture.state {
case UIGestureRecognizerState.began :
guard let selectedIndexPath = self.collectionView?.indexPathForItem(at: gesture.location(in: …Run Code Online (Sandbox Code Playgroud) 如何轻松地创建一个水平滚动集合视图,填充单元格跨越行而不是列向下?
我希望有5列和3行,但当有超过15项时,我希望它滚动到下一页.
这件事我有很多麻烦.
horizontal-scrolling ios uicollectionview uicollectionviewcell swift
从上图我有UICollectionView4个自定义单元格.任何时候屏幕上都可以有2或3个单元格.如何判断屏幕上"单元格1"或"单元格2"何时为100%?
都
collectionView.visibleCells
collectionView.indexPathsForVisibleItems
Run Code Online (Sandbox Code Playgroud)
返回数组并不会告诉你屏幕上是否有100%的单元格.
在图像的情况下,将显示以下内容 didSelectItemAt
collectionView.visibleCells
[<Shot_On_Goal.MainCollectionViewCell: 0x101f525c0; baseClass = UICollectionViewCell; frame = (190 7.66667; 454 350); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0237300>>, <Shot_On_Goal.HeaderCollectionViewCell: 0x101f4d580; baseClass = UICollectionViewCell; frame = (10 0; 170 365); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0236800>>, <Shot_On_Goal.TheirHockeyNetCollectionViewCell: 0x101f55520; baseClass = UICollectionViewCell; frame = (654 7.66667; 454 350); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0238fe0>>]
Run Code Online (Sandbox Code Playgroud)
collectionView.indexPathsForVisibleItems
[[0, 1], [0, 0], [0, 2]]
Run Code Online (Sandbox Code Playgroud) uicollectionview ×10
ios ×8
swift ×7
alamofire ×1
ios6 ×1
ios7 ×1
iphone ×1
nsindexpath ×1
xcode ×1