Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS5 Assign a .xib to a custom UIView class
    primarykey
    data
    text
    <p>HI have a custom view class that is loaded and placed within my main view using the following code. The reason it that i want to populate it with different content so rather than build a view in code each time if I create a custom class i can reuse this in a loop etc, I got this to work just fine in code, that is laying out the buttons label etc.</p> <p>But rather than hand code it all I thought if i create a new User Interface View, then construct visually my text fields, labels and buttons on this view.</p> <p>Then connect it to my custom class.</p> <p>Bu this is where I am having an issue, how do I connect this view xib file so that it becomes visible when placed on my my code. I have assigned the custom class attribute within the xib file to my custom file, but what else am i missing? </p> <p>.h File:</p> <pre><code> #import &lt;UIKit/UIKit.h&gt; @interface blogView : UIView @end </code></pre> <p>.m File:</p> <pre><code> #import "blogView.h" @implementation blogView - (id)init { self = [super initWithFrame:CGRectMake(0, 0, 478, 220)]; if (self != nil) { NSLog(@"Blog View loaded"); self.backgroundColor = [UIColor yellowColor]; UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 400, 40)]; [titleLbl setText:@"This is the Title"]; [self addSubview:titleLbl]; } return self; } @end </code></pre> <p>my xib file has the same name blogView.xib which is a View User Interface.</p> <p>Within my main view controller and in the ViewDidLoad i have</p> <pre><code> blogView *blogItem = [[blogView alloc]init]; [self.view addSubview:blogItem]; </code></pre> <p>When I run this is all works fine, but I would like to link to a .xib file to save time etc. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload