【问题标题】:UIStoryboard - OutletCollectionUIStoryboard - OutletCollection
【发布时间】:2012-10-03 17:01:13
【问题描述】:
我正在使用 nib 文件来构建用户界面,但现在我切换到 storyboard 并发现了一个问题。
在 nib 文件中,我已经部署了 10 个按钮,我曾经参与按钮 - IBOutletCollection (UIButton *) NSArray
第一个按钮的值为 0,第二个为 2,依此类推(在 OutletCollection Array 中)。
但是使用 UIStoryBoard 按钮是随机放置的。
有人知道如何解决这个问题吗?
感谢您的回答:)
【问题讨论】:
标签:
objective-c
ios
xcode
uibutton
storyboard
【解决方案1】:
我为解决这个问题所做的就是设置我添加到我的 outletcollection 的 UIViews 的标签,然后将它添加到我的 viewDidLoad...
NSComparator compareTags = ^(id a, id b) {
NSInteger aTag = [a tag];
NSInteger bTag = [b tag];
return aTag < bTag ? NSOrderedAscending
: aTag > bTag ? NSOrderedDescending
: NSOrderedSame;
};
self.UIViewCollection = [self.UIViewCollection sortedArrayUsingComparator:compareTags];
现在我的 UIView 的顺序是 1-20。 outlet-collection 只是一个对象数组。