ICL1901
ICL1901

Reputation: 7778

How do I load UIView subview

I'm trying to use a nice looking control, but cannot figure a) how to load data and b) how to convert this control to a storyboard.

The control is here

My code to load the titles of subviews works fine.

-(NSString *)titleForCollapseClickAtIndex:(int)index {
    //NSLog(@"%s", __FUNCTION__);

    switch (index) {
        case 0:
            return @"Item Information";
            break;
        case 1:

I cannot figure how to load this next method:

-(UIView *)viewForCollapseClickContentViewAtIndex:(int)index {
    NSLog(@"%s", __FUNCTION__);
    switch (index) {
        case 0:
            return  itemView;
            break;

(UIView *) ItemView (after initializing) is:

- (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;

The view is drawn in IB, and has connections to these items. The UIView is also drawn in the main xib. It gets to show as in the demo, with titles from the ItemView class.

As I mentioned, the titles are inherited from the view controller. The text (e.g. @ try this", do not..

If I try to log a text field in the "viewForCollapseClickContentViewAtIndex" method, I get an run time exception:

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

Upvotes: 0

Views: 128

Answers (1)

Caleb
Caleb

Reputation: 124997

[self.item setText: @"try this"];

This is the cause of your exception. self (which seems to be your control) doesn't have an item property. self.item is equivalent to [self item], and since there's no method named item, you get an unrecognized selector exception.

Once you get it working, you can add it to a storyboard by adding a scroll view to the storyboard (because your widget is a subclass of UIScrollView) and then changing its class to CollapseClick. AFAIK, there's not currently a way to add user-defined classes to the list of classes supported by the storyboard editor.

Upvotes: 1

Related Questions