我有一个iPad应用程序,使用Storyboard,Tab Bar和XCode 4.5.我的一个场景在左上象限中有一个UITableView,在右上象限中有标签和UITextBox.
当我点击第二个标签时,我将进入上述场景.这是代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"MY_CELL"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 4;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; {
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
cell.label.text = [NSString stringWithFormat:@"%d",indexPath.item];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
这是接口定义:
@interface ClientViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource> {
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UIView collectionView:numberOfItemsInSection:]:无法识别的选择器发送到实例0x7d925b0'
如您所见,我对numberOfSectionsInCollectionView使用了相同的代码.我研究过SO和Google,但没有发现任何适用的内容.
我究竟做错了什么?
objective-c ios xcode4.5 uicollectionview uicollectionviewcell
我有一个水平滚动UICollectionView与UICollectionViewCells包含一个UITextView.有没有办法将textview上的手势传递给单元格,以便调用didSelectItemAtIndexPath?我尝试使用子类化UITextView并将touchesbegin/end传递给单元格,但这没有用.
在用户按下我的收集单元格中的按钮后,我正在设置ActivityIndicator,同时我等待网络响应.下面的代码由自定义单元格的每个实例调用(在调试器中确认),但活动指示器仅在第一个单元格中单击按钮时显示,或者在重用第一个单元格的单元格中单击时显示.如果我在第一个单元格之前单击另一个单元格中的按钮并不重要.
customCollectionViewCell.m
@interface customCollectionViewCell(){
UIActivityIndicatorView *activityIndicator;
}
@implementation cutomCollectionViewCell
- (void) choiceClicked:(id)sender{
dispatch_async(dispatch_get_main_queue(), ^{
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actvityIndicator.center = self.center;
[self.contentView addSubview:activityIndicator];
[actvityIndicator startAnimating];
});
async - network stuff
}
Run Code Online (Sandbox Code Playgroud)
我正在确保准备重用,我正在从superview中删除指标并设置为nil.
我也尝试过只创建指标,如果它不存在并开始动画 - 行为仍然没有变化.
编辑:如果仅从主线程调用动画并且其他调用明确地是默认队列的一部分也无关紧要.
if (activityIndicator == nil){
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.center = self.center;
[self.contentView addSubview:activityIndicator];
}
dispatch_async(dispatch_get_main_queue(), ^{
[activityIndicator startAnimating];
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
network call
});
Run Code Online (Sandbox Code Playgroud) uiactivityindicatorview ios uicollectionview uicollectionviewcell
UICollectionView用于显示图像.它工作正常.
问题是当我滚动时UICollectionView,一些可见的单元格现在是不可见的,当我向后滚动以便它们再次可见时,我看到它们没有正确显示.
所以发生的imageA是在索引0并且imageB在索引1处.现在在滚动并且在再次加载这些单元格时返回原始滚动位置时,它们的位置被切换或者两个单元具有相同的图像.
原来 :

重新加载单元格后:

代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell"
forIndexPath:indexPath];
DLog(@"url at index %d : %@", indexPath.row, ((MyObject *)[self.list.array objectAtIndex:indexPath.row]).imageUrl);
MyObject *object = (MyObject *)[self.list.array objectAtIndex:indexPath.row];
// Get image in separate thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Get image to display
UIImage * tempImage = object.image;
if (tempImage)
{
// Run code to set image to UIImageView in main thread only.
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image …Run Code Online (Sandbox Code Playgroud) 根据过滤结果,我需要更改集合视图的流布局,并使用不同类型的单元格重新加载数据.但是你不能这样做:
myCollectionView.flowLayout = ...
Run Code Online (Sandbox Code Playgroud)
那么如何更改集合视图的流布局呢?
ios uicollectionview uicollectionviewcell uicollectionviewlayout
我正在尝试使用4种不同的类型创建多个collectionViewCells.并且每个单元格对这4种类型中的一种具有不同的视图.根据用户选择,这些类型的每个视图都可以具有不同的内容.
我遇到的问题是,当屏幕上有多个相同类型的视图/单元时,某些卡重叠/未正确加载.
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Card *card = [[[usermanager getSelectedUser] getCards] objectAtIndex:indexPath.item];
NSLog(@"CARD LOADING: %@", card.title);
[card setupLayout];
UICollectionViewCell *cell;
if(card.type.intValue == 1){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"lifestyleCell" forIndexPath:indexPath];
}else if(card.type.intValue == 2){
cell= [collectionView dequeueReusableCellWithReuseIdentifier:@"sceneCell" forIndexPath:indexPath];
}else if(card.type.intValue == 3){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"energyCell" forIndexPath:indexPath];
}else if(card.type.intValue == 4){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productCell" forIndexPath:indexPath];
}else{
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cardCell" forIndexPath:indexPath];
}
[cell addSubview:card];
//Add dropshadow
cell.contentView.layer.borderWidth = 1.0f;
cell.contentView.layer.borderColor = [UIColor clearColor].CGColor;
cell.contentView.layer.masksToBounds = YES;
cell.layer.shadowColor = …Run Code Online (Sandbox Code Playgroud) user-interface objective-c ios uicollectionview uicollectionviewcell
我有一个UITableViewCells 列表,每个都有一个UICollectionViewX的数量UICollectionViewCells(为了更清晰,见下图)
这背后的想法是能够实现顶部带有标题和水平滚动的部分 UICollectionView
一切都很好,除非我试图集中UICollectionViewCells(又名:)CategoryCell.该UITableViewCell被关注,并强调所有使其无法集中的任何内容UICollectionViewCell秒.
根据其他帖子,对此的修复将停用用户交互和/或将选择样式设置为无UITableViewCell:
cell.selectionStyle = UITableViewCellSelectionStyle.None
Run Code Online (Sandbox Code Playgroud)
并改为启用用户交互UICollectionViewCell.
以下是谈论它的帖子:
UITableViewCell与UITextField失去了选择UITableView行的能力?
我试图实现这些解决方案但没有成功.
我错过了什么步骤?该修复程序不适用于tvOS吗?我如何专注我的UICollectionViewCell是一个UICollectionView是一个UITableViewCell?
图像显示了我的UITableViewController以及我的StoryBoard中的所有内容.
uitableview uicollectionview uicollectionviewcell swift tvos
我有一个UICollectionView有一堆单元格.当我选择这些单元格时,它们会改变颜色,看起来好像已经明确选择了,我将hashtag.hashtag_name(String)附加到我的hashtagsArray.如果我点击一个类别(时尚,食物,爱好或音乐),我会将另一个数组附加到该索引路径,以便为用户提供该特定类别的单元格,如下图所示.
我想要的是,如果我将已经SELECTED的单元格点击为UNSELECT它,那么hashtag.hashtag_name将从我的hashtagArray中删除.问题是,当我将其添加到hashtagArray中时,我添加的数组的indexPath与数组indexPath完全不同,因此我无法通过调用将其删除self.hashtagArray.remove(Int).这是我的代码......

import UIKit
class Hashtag: NSObject {
var hashtag_name: String?
var hashtag_color: String?
}
import UIKit
private let reuseIdentifier = "Cell"
class HashtagView: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var hashtagArray: [String] = []
var categoriesArray = [Hashtag]()
var fashionArray = [Hashtag]()
var isFashionSelected: Bool = false
var fashionArrayCount: [Int] = []
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = .white
navigationItem.title = "Hashtag"
self.collectionView?.backgroundColor = .white
self.collectionView?.register(HashtagCell.self, forCellWithReuseIdentifier: reuseIdentifier)
self.collectionView?.contentInset = UIEdgeInsetsMake(10, 0, 0, 0)
handleFetchCategories()
handleFetchFashionHashtags()
}
func insertCategoryAtIndexPath(element: …Run Code Online (Sandbox Code Playgroud) 我想创建一个应用程序,类似于iOS上的10苹果新闻应用程序的布局有喜欢的不同部分Top Stories,For you等我都放在一个事先知情同意For You下面的章节:
上面的布局在顶部有一篇大文章(120亿加仑的水文章),然后是2篇水平文章(Ron howard和google cloud),最后是两篇垂直文章(philando castile和Daniel Day-lewis).
我的问题是如何实现这一目标?我在想什么是你有多个部分的UICollectionView(对于部分For you,Technology,Politics等),每个部分都有一个主UICollectionView细胞.然后在该主单元格中,您还有另外3个不同的单元格(一个用于大文章,一个用于垂直文章,一个用于水平文章).这是实现这一目标的好方法吗?就像为一个创建这么多单元格一样UICollectionView?
我试图以编程方式将收集单元格的大小设置为框架的宽度,但是,当我运行应用程序时,单元格大小不会改变.这是调用Swift 4和Xcode 9的正确功能吗?
import UIKit
class SettingsLauncher: NSObject, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewFlowLayout {
let blackView = UIView()
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.white
return cv
}()
let cellID = "cell"
@objc func showMenu() {
// Show menu
if let window = UIApplication.shared.keyWindow { // Get the size of the entire window
blackView.backgroundColor = UIColor(white: 0, alpha: 0.5)
let height: CGFloat = 200
let y = window.frame.height - height …Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×3
swift ×3
arrays ×1
ios7 ×1
swift3 ×1
swift4 ×1
tvos ×1
uitableview ×1
uitextview ×1
xcode4.5 ×1