我正在尝试使用外观漂亮的控件,但无法想象a)如何加载数据和b)如何将此控件转换为故事板。
控件为here
我加载子视图标题的代码运行正常。
-(NSString *)titleForCollapseClickAtIndex:(int)index {
//NSLog(@"%s", __FUNCTION__);
switch (index) {
case 0:
return @"Item Information";
break;
case 1:
我无法想出如何加载下一个方法:
-(UIView *)viewForCollapseClickContentViewAtIndex:(int)index {
NSLog(@"%s", __FUNCTION__);
switch (index) {
case 0:
return itemView;
break;
(UIView *)ItemView(初始化后)是:
- (void)loadElements
{
NSLog(@"%s", __FUNCTION__);
[self.item setText: @"try this"];
self.category.text = @"category";
self.date1.text = @"todays date";
self.date2.text = @"another date";
self.serial.text = @"serial no";
} return self;
视图在IB中绘制,并且与这些项目有关联。 UIView也在主xib中绘制。它在演示中显示,带有ItemView类的标题。
正如我所提到的,标题是从视图控制器继承的。文字(例如@ 试试这个“,不要......
如果我尝试在“viewForCollapseClickContentViewAtIndex”方法中记录文本字段,则会出现运行时异常:
2014-01-17 07:54:44.856 CollapseClickDemo[29037:70b] -[UIView item]: unrecognized selector sent to instance 0x8c84590
2014-01-17 07:54:44.858 CollapseClickDemo[29037:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView item]: unrecognized selector sent to instance 0x8c84590'
*** First throw call stack:
(
0 CoreFoundation 0x024531e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x015808e5 objc_exception_throw + 44
2 CoreFoundation 0x024f0243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0244350b ___forwarding___ + 1019
4 CoreFoundation 0x024430ee _CF_forwarding_prep_0 + 14
5 CollapseClickDemo 0x000034b8 -[ViewController viewForCollapseClickContentViewAtIndex:] + 152
6 CollapseClickDemo 0x0000ca89 -[CollapseClick reloadCollapseClick] + 1561
答案 0 :(得分:1)
[self.item setText: @"try this"];
这是您的例外原因。 self
(似乎是您的控件)没有item
属性。 self.item
相当于[self item]
,由于没有名为item
的方法,因此您会收到无法识别的选择器异常。
一旦你开始工作,你可以通过向故事板添加滚动视图(因为你的小部件是UIScrollView的子类),然后将其类更改为CollapseClick
,将它添加到故事板。 AFAIK,目前没有办法将用户定义的类添加到情节提要编辑器支持的类列表中。