我一直在使用Brian Mann的BackboneRails截屏视频,所以我的应用程序结构完全符合这些.
以下定义了HomepageApp Marionette Appication的"show"部分.
My.module('HomepageApp.Show', function(Show, App, Backbone, Marionette, $, _){
Show.Photo = Marionette.ItemView.extend({
tagName:'span'
});
Show.Photos = Marionette.CollectionView.extend({
template: 'homepage/show/templates/photos',
itemView:Show.Photo,
itemViewContainer: '#photos'
});
Show.Layout = Marionette.Layout.extend({
template: 'homepage/show/templates/layout',
regions:{
photoRegion: '#photo-region'
}
});
});
Run Code Online (Sandbox Code Playgroud)
我也用以下内容覆盖Marionette.Renderer.render函数:
Backbone.Marionette.Renderer.render = function(template, data){
var path = JST["backbone/apps/" + template];
try{
if(!path) throw({message: "Template '" + template + "' not found!"});
return path(data);
}
catch(err){
console.log(err.message);
}
}
Run Code Online (Sandbox Code Playgroud)
我的所有观点,包括许多未在此处显示的观点都完美无缺.问题是Show.Photos CollectionView的'模板'属性在我的渲染器覆盖中变为'undefined',给出了以下错误:
Template 'undefined' not found!
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我根本没有为模板属性传递任何值时,甚至会发生这种情况.
我也知道我在实例化时传递了一个有效的Backbone集合.
我完全陷入了困境.有谁熟悉这种现象?
有没有办法在Marionette CollectionView中创建一个独特的视图?我的意思是这样的:
的CollectionView
通过唯一,我的意思是"Start ItemView"必须使用唯一的模板,而不是与常规ItemViews相关联的方法.
我试过的事情:
只是将开始视图添加到CollectionView的el之前是不可取的,因为我的CollectionView的方法作用于其子视图.
在Marionette文档中,建议在这种情况下覆盖buildItemView(我认为?).我不知道如何覆盖它.只是调用buildItemView不起作用,因为StartView没有关联的模型或任何选项.好像我不能把这些args留下来,或者只是返回undefined.
我不能在我的CollectionView模板中包含StartView的标记,因为... Marionette CollectionViews不能有模板.
从Marionette文档来看,它似乎不适合CompositeView的用例.但也许我错了.
我可能错过了一些相当明显的东西.在此先感谢您的帮助.
编辑:格式化
我正在建立一个网站,其博客有一些特点.这是一种tumblr式的体验,其中有不同的后期类型:
这些职位都有一些共同的属性,如id
,title
,post_date
,post_url_slug
,但一些有一个post_image
或post_external_link
为例.这是所有依赖的post_type
,能容纳值,例如facebook
,quote
,article
等这将是一个很好的策略,以确定哪种类型的它渲染时Marionette.CollectionView
,要么干脆选择不同tempalte或在下划线的任意JavaScript处理这个模板我的模板?任何输入将不胜感激.
谢谢!
我在一个单元格中设置了一个包含10个子视图的集合视图.
子视图是带有标签的-imageview -text view -imageview -uilabel -imageview -uilabel
最初,集合视图在iPad上显示15个单元格.当我需要更换底部或顶部的单元格(重复使用单元格)时,滚动暂停时滚动暂停.我删除了阴影,但仍然是同样的问题.
因此,当旧单元被重用时导致滞后时会出现问题.
顺便说一句,没有图像通过网络加载.
我们正在尝试收集视图。用户可以在每个单元格中选择一个图像,然后在文本字段中输入文本。我们注意到,在添加四个单元格之后,当我们添加一个新的单元格时,文本字段已经充满了先前单元格中的信息。在我们的代码中,我们永远不会以编程方式填充文本字段(该字段以空开头),我们允许用户执行此操作。有什么建议么?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Image", forIndexPath: indexPath) as! CollectionViewCell
cell.deleteButton?.addTarget(self, action: #selector(AddNewItem.xButtonPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside)
cell.deleteButton?.layer.setValue(indexPath.row, forKey: "index")
let item = items[indexPath.item]
let path = getDocumentsDirectory().stringByAppendingPathComponent(item.image)
cell.imageView.image = UIImage(contentsOfFile: path)
cell.imageView.layer.borderColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3).CGColor
cell.imageView.layer.borderWidth = 2
cell.layer.cornerRadius = 7
return cell
}
Run Code Online (Sandbox Code Playgroud) 我有一个运行的CollectionView和一个XLPagerTabStrip也运行,但是当我将我的CollectionView集成在IndicatorInfoProvider中的XLPagerTabStrip中时,我有这个错误...
谢谢!
collectionview uicollectionview swift swift2 xlpagertabstrip
好的,我在处理集合视图时遇到了问题。这就是我想要实现的 - 1 个大的 MAIN 页眉和页脚,然后嵌套在里面,需要一些数量(例如:4)个部分都只有 HEADERS。像这样:
------
tiny header 1
------
[a][b][c]
------
tiny header 2
------
[a][b][c]
Run Code Online (Sandbox Code Playgroud)
查看类似的答案,我首先尝试创建不同的小节,因为现在我只有所有集合视图单元格以及一个大页脚和页眉。问题是不管我有什么,我只剩下 1 节:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 4
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么。我从情节提要中获取我的收藏视图并将其设置如下:
@IBOutlet var collectionView: UICollectionView!
self.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) //-44
self.collectionView.backgroundColor = UIColor.white
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerCell", for: indexPath as …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用UICollectionView构建通用表单构建器.
每个表单元素都是一个单元格,对于复选框,我在单元格内部使用UIStackView来显示所有可用选项.
问题是,每次我重复使用单元格时,即使我删除了所有已排列的子视图,它们也会在新视图中保留.
以下代码是我正在做的简化版本:
class cell: UICollectionViewCell {
@IBOutlet weak var stackView: UIStackView!
func setup(options: [String]) {
for option in options {
let label = UILabel()
label.text = option
stackView.addArrangedSubview(label)
}
}
override func prepareForReuse() {
super.prepareForReuse()
optionsStackView.arrangedSubviews.forEach({ optionsStackView.removeArrangedSubview(view: $0) })
}
}
Run Code Online (Sandbox Code Playgroud)
而不是那样,我目前的解决方法是在prepareForReuse()中隐藏()每个arrangeSubview而不是删除它们,但我不喜欢它.
目前我的 UICollectionView 中有一个标题单元格。当我尝试滚动 UICollectionView 时,标题单元格将与 UICollectionView 列表一起滚动。我可以知道如何将标题单元格设置在顶部吗?请帮忙。谢谢。
这是我的 ViewController 中标题单元格的示例代码:-
- (UICollectionView *)collectionView
{
if (!_collectionView) {
DCHoverFlowLayout *layout = [DCHoverFlowLayout new];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.frame = CGRectMake(0, DCTopNavH, ScreenW, ScreenH - DCTopNavH);
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[Product_HeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:Product_HeadViewID];
}
return _collectionView;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader){
Product_HeadView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:Product_HeadViewID forIndexPath:indexPath]; …
Run Code Online (Sandbox Code Playgroud) 我有一个 ObservableCollection 和一个使用 OC 作为源的 ICollectionView:
private ObservableCollection<Comment> _Comments = new ObservableCollection<Comment>();
/// <summary>
/// Comments on the account
/// </summary>
[BsonElement("comments")]
public ObservableCollection<Comment> Comments
{
get
{
return _Comments;
}
set
{
_Comments = value;
OnPropertyChanged("Comments");
OnPropertyChanged("CommentsSorted");
}
}
private ICollectionView _CommentsSorted;
/// <summary>
/// Sorted list (reverse order) of the comments
/// </summary>
[BsonIgnore]
public ICollectionView CommentsSorted
{
get
{
return _CommentsSorted;
}
set
{
_CommentsSorted = value;
OnPropertyChanged("CommentsSorted");
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个命令,运行:
obj.Comments.Add(new Comment(Message));
Run Code Online (Sandbox Code Playgroud)
其中 obj 是包含可观察集合的类的实例。
调用此行时,我遇到以下异常: …
collectionview ×10
ios ×4
backbone.js ×3
marionette ×3
swift ×3
c# ×1
header ×1
objective-c ×1
performance ×1
scroll ×1
stackview ×1
swift2 ×1
swift3 ×1
tableview ×1
xcode ×1