Rectangle 27 23

The reason it's calling the initWithCoder so many times is due to wrong class setup in your .xib file.

Make sure the Custom Class on the File's Owner is your custom UIView class:

And make sure the class on the root View is the default UIView:

And now this is all you need in your custom class (in Swift):

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    let view = NSBundle.mainBundle().loadNibNamed("TopMenuView", owner: self, options: nil)[0] as! UIView
    self.addSubview(view)
    view.frame = self.bounds
}

This really solves the problem. Just felt that Xcode should have provided better warnings to these kind of custom class configurations.

Also note that, if your custom class is from another project, like a Cocoapods dependency, then you need to fill in the Module field too (just below the custom class).

ios - EXC_BAD_ACCESS on custom UIView with custom XIB - Stack Overflow

ios objective-c uiview
Rectangle 27 9

You are most likely getting into an infinite loop because you're recursively calling initWithCoder. One workaround is to check if your subclass has any subviews first.

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        if (self.subviews.count == 0) {
            NSArray *topMenuView = [[NSBundle mainBundle] loadNibNamed:@"TopMenuView" owner:nil options:nil];
            UIView *nv = [topMenuView objectAtIndex:0];
            [self addSubview:self.view];
        }
    }
    return self;
}

ios - EXC_BAD_ACCESS on custom UIView with custom XIB - Stack Overflow

ios objective-c uiview
Rectangle 27 3

//Add Custom View to my main view of viewcontroller
self.customNavView = [[CustomNavigationView alloc] init];
self.customNavView = [[[NSBundle mainBundle] loadNibNamed:@"CustomNavigationView" owner:self options:nil] objectAtIndex:0];
[self.customNavView setFrame:CGRectMake(0, 20, 320, 54)];
[self.view addSubview:self.customNavView];

Here CustomNavigationView is a UIView subclass with Files Owner Class as UIView and the UIView custom class as CustomNavigationView.

Works great! You can remove the initWithCoder override

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

ios - EXC_BAD_ACCESS on custom UIView with custom XIB - Stack Overflow

ios objective-c uiview
Rectangle 27 1

TopMenuView
initWithCoder:
- (id)initWithCoder:(NSCoder *)aDecoder

and where you want to use TopMenuView probably in some controller use the below code

NSArray *topMenuView = [[NSBundle mainBundle] loadNibNamed:@"TopMenuView" owner:nil options:nil];
UIView *nv = [topMenuView objectAtIndex:0];

Yes, I know that. How can I fix it?

ios - EXC_BAD_ACCESS on custom UIView with custom XIB - Stack Overflow

ios objective-c uiview
Rectangle 27 5

Let's say you named your UIView subclass MyCustomView. When adding an UIView from interface-builder (xib or storyboard), you MUST explicitly set the custom class of the UIView from interface builder to be MyCustomView (like in this answer).

Another problem that might occur is the order of the views. Which one is on top?

Adding the custom view from code is another way to do it.

Your drawing code seems ok. Here is my code from drawRect that draws an image in the background (I tweaked it a little bit):

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);

    // here I draw an image BEFORE drawing the rectangles
    UIImage* img = [UIImage imageNamed:@"img.jpg"];
    [img drawInRect:rect];

    CGFloat height = self.bounds.size.height;
    CGFloat barWidth = 30;

    CGContextSetFillColorWithColor(context, [[UIColor grayColor] CGColor]);

    int count = 0;
    NSArray *values = [NSArray arrayWithObjects:@1, @0.5, nil];
    for (NSNumber *num in values) {
        CGFloat x = count * (barWidth + 10);
        CGRect barRect = CGRectMake(x, height - ([num floatValue] * height), barWidth, [num floatValue] * height);

        // drawing rectangles OVER the image
        CGContextFillRect(context, barRect);
        count++;
    }
}

ios - Cant drawing rectangles over image in custom UIView - Stack Over...

ios uiview uiviewcontroller drawrect
Rectangle 27 15

You need to implement awakeAfterUsingCoder: in your custom UIView subclass. This method allows you to exchange the decoded object (from the storyboard) with a different object (from your reusable xib), like so:

- (id) awakeAfterUsingCoder: (NSCoder *) aDecoder
{
    // without this check you'll end up with a recursive loop - we need to know that we were loaded from our view xib vs the storyboard.
    // set the view tag in the MyView xib to be -999 and anything else in the storyboard.
    if ( self.tag == -999 )
    {
        return self;
    }

    // make sure your custom view is the first object in the nib
    MyView* v = [[[UINib nibWithNibName: @"MyView" bundle: nil] instantiateWithOwner: nil options: nil] firstObject];

    // copy properties forward from the storyboard-decoded object (self)
    v.frame = self.frame;
    v.autoresizingMask = self.autoresizingMask;
    v.translatesAutoresizingMaskIntoConstraints = self.translatesAutoresizingMaskIntoConstraints;
    v.tag = self.tag;

    // copy any other attribtues you want to set in the storyboard

    // possibly copy any child constraints for width/height

    return v;
}

There's a pretty good writeup here discussing this technique and a few alternatives.

Furthermore, if you add IB_DESIGNABLE to your @interface declaration, and provide an initWithFrame: method you can get design-time preview to work in IB (Xcode 6 required!):

IB_DESIGNABLE @interface MyView : UIView
@end

@implementation MyView

- (id) initWithFrame: (CGRect) frame
{
    self = [[[UINib nibWithNibName: @"MyView"
                            bundle: [NSBundle bundleForClass: [MyView class]]]

             instantiateWithOwner: nil
             options: nil] firstObject];

    self.frame = frame;

    return self;
}

This is definitely preferable to the "use a second wrapping view and add your real view as a subview in initWithCoder" slapdashery. Any heavy context porting can be done in a category/extension method. One suggestion to remove a bit of the configuration: presumably you have subviews in the xib, otherwise it would be pointless, so one might rely on subviews being empty or not instead of the tag property.

ios - How to embed a custom view xib in a storyboard scene? - Stack Ov...

ios objective-c xcode interface-builder uistoryboard
Rectangle 27 100

Reuse and render a xib in a storyboard.

//  DesignableXibView.swift

import UIKit

@IBDesignable

class DesignableXibView: UIView {

    var contentView : UIView?

    override init(frame: CGRect) {
        super.init(frame: frame)
        xibSetup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        xibSetup()
    }

    func xibSetup() {
        contentView = loadViewFromNib()

        // use bounds not frame or it'll be offset
        contentView!.frame = bounds

        // Make the view stretch with containing view
        contentView!.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

        // Adding custom subview on top of our view (over any custom drawing > see note below)
        addSubview(contentView!)
    }

    func loadViewFromNib() -> UIView! {

        let bundle = NSBundle(forClass: self.dynamicType)
        let nib = UINib(nibName: String(self.dynamicType), bundle: bundle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

        return view
    }

}
  • Add a view

Thanks! You may want to add an example using constraints with Swift, as you did in your Obj-C answer (with and without VFL).

I was able to get it working with constraints, although didn't test with live rendering. I added CenterX, CenterY, Width, and Height constraints and it worked fine. I can email you sample code or post an answer on here.

In my xib, I've got some outlets and such to a couple of views and buttons. The code fails in xibSetup() at the line contentView = loadFromNib(), it fails due to "this class is not key value coding-compliant for the key <whatever>". I tried making contentView my view class, but that still didn't work.

I answered my own question, it looks like I setup the outlets BEFORE i read these SO articles saying to set the File Owner, not the view. It worked after I disconnected all of the outlets, ensured the file owner was correct, and then re-added all of the outlets.

What's the difference between setting file owner vs custom class?

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

autolayout - Reuse a uiview xib in storyboard - Stack Overflow

uiview autolayout interface-builder uistoryboard xib
Rectangle 27 99

Reuse and render a xib in a storyboard.

//  DesignableXibView.swift

import UIKit

@IBDesignable

class DesignableXibView: UIView {

    var contentView : UIView?

    override init(frame: CGRect) {
        super.init(frame: frame)
        xibSetup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        xibSetup()
    }

    func xibSetup() {
        contentView = loadViewFromNib()

        // use bounds not frame or it'll be offset
        contentView!.frame = bounds

        // Make the view stretch with containing view
        contentView!.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

        // Adding custom subview on top of our view (over any custom drawing > see note below)
        addSubview(contentView!)
    }

    func loadViewFromNib() -> UIView! {

        let bundle = NSBundle(forClass: self.dynamicType)
        let nib = UINib(nibName: String(self.dynamicType), bundle: bundle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

        return view
    }

}
  • Add a view

Thanks! You may want to add an example using constraints with Swift, as you did in your Obj-C answer (with and without VFL).

I was able to get it working with constraints, although didn't test with live rendering. I added CenterX, CenterY, Width, and Height constraints and it worked fine. I can email you sample code or post an answer on here.

In my xib, I've got some outlets and such to a couple of views and buttons. The code fails in xibSetup() at the line contentView = loadFromNib(), it fails due to "this class is not key value coding-compliant for the key <whatever>". I tried making contentView my view class, but that still didn't work.

I answered my own question, it looks like I setup the outlets BEFORE i read these SO articles saying to set the File Owner, not the view. It worked after I disconnected all of the outlets, ensured the file owner was correct, and then re-added all of the outlets.

What's the difference between setting file owner vs custom class?

autolayout - Reuse a uiview xib in storyboard - Stack Overflow

uiview autolayout interface-builder uistoryboard xib
Rectangle 27 10

  • Set the File's Owner of the .xib to class name of your custom view.
  • Don't set the custom class name in IB for the .xib's root view.

I came to this Q&A page several times while learning to make reusable views. Forgetting the above points made me waste a lot of time trying to find out what was causing infinite recursion to happen. These points are mentioned in other answers here and elsewhere, but I just want to reemphasize them here.

ios - Creating a reusable UIView with xib (and loading from storyboard...

ios objective-c uiview storyboard nib
Rectangle 27 10

  • Set the File's Owner of the .xib to class name of your custom view.
  • Don't set the custom class name in IB for the .xib's root view.

I came to this Q&A page several times while learning to make reusable views. Forgetting the above points made me waste a lot of time trying to find out what was causing infinite recursion to happen. These points are mentioned in other answers here and elsewhere, but I just want to reemphasize them here.

ios - Creating a reusable UIView with xib (and loading from storyboard...

ios objective-c uiview storyboard nib
Rectangle 27 1

Alloc init will not load the nib of your custom UIView as in ViewControllers. You should load the nib using the below code after alloc init

Suppose you have CustomView.h, CustomView.m, CustomView.xib

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
    yourView = (CustomView *)[nib objectAtIndex:0];

UIView with Separated .h, .m and xib files - Stack Overflow

uiview xib
Rectangle 27 2

a) should the NIB load automatically somehow if named the name as the *.h & *.m file? (i.e. I'm talking about a custom UIView here, not a UIControllerView)

As far as I know, nibs are not loaded automatically, except for MainWindow, which is loaded by UIKit according to what it specified in info.plist;

loadNibNamed is a good option if you do not want to instantiate a view controller and need just an array of the top object you defined in your nib;

c) if yes (to b above), then in whether method do you do this, in the custom view's "- (id)initWithCoder:(NSCoder *)coder" method?

I would use initWithCoder if you are loading the base view from a nib, initWithFrame if you create it programmatically.

As to your PS, I guess that you set one of the object in your xib file to be an instance of the UIView subclass where you define initWithCoder. (e.g., if your UIView subclass is MyView, then you also instantiated a view object in the xib and set its class to MyView).

If this is the case, what you need to do is define the File's Owner to the concrete derived UIView class (e.g., MyView); indeed you are already instantiating the UIView derived class and when loading the nib you only need specifying the file's owner (through the owner argument).

After reading your comment, you have two ways of doing it.:

In this case, you would define initWithCoder as you did previously. Drawback of this is that you instantiate objects in one nib and the view in the other; you won't be able to define the clockview view in the second nib. So,...

I think that this second case is the one that you are aiming at. In this case, you don't need to do anything specific in your clockview's initWithCoder; what you need is, in your UIViewController, load the xib view when appropriate; typically this could be in viewDidLoad (or elsewhere, possibly after you click on a button, it depends on your app):

- (void)viewDidLoad {
     [super viewDidLoad];
     NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"ClockView" owner:self options:nil];
     for (NSObject *obj in nibs) {
        if ( [obj isKindOfClass:[clockview class]]) {
            [self addSubview:(clockview*)obj];
            break;
        }
     }
  }

What I am doing in this viewDidLoad is identifying the clockwork view that is instantiated by loading the second xib file; and adding it to the controller's view as a subview.

Again, observe the controller argument that I passed to loadNibNamed; this must correspond to the object you specified as file's owner of the second xib.

I think that it should work in this way.

thanks Sergio - I posted a PS to my question as when I try this I'm getting a recursive loop of hits to "initWithCoder"?

oh actually I see that in fact I have (a) in the parent UIControllerView which uses my custom view, in IB for it's XIB I use a UIView which I've set the classname to "clockview", but then (b) in my actual clockview custom UIView (not UIControllerView) XIB file I've done the same thing and set the class name to be "clockview". Do you know what classname I should be using for (a) parent UIControllerView and (b) the custom UIView itself here? (getting a bit confused)

Based on seeing stackoverflow.com/questions/4869424/ . Perhaps I could create a custom UIView but only ever use via creating/instantiating it programmatically from the UIControllerView I'm calling it from?

thanks sergio - just digesting this at the moment :) - will let you know how I go

iphone - how to I introduce use of a NIB file to my existing custom UI...

iphone ios uiview
Rectangle 27 5

I have found my mistake , it's about file owner , i have change it in the inspector but by selecting the uiview and not te file's owner , i change NSObject to my class name and reconnect the label .

ios - Change UILabel text of custom UIView doesn't work - Stack Overfl...

ios objective-c ipad uiview xib
Rectangle 27 4

Open any of your view controllers and paste this code into your viewDidAppear method:

NSArray * allTheViewsInMyNIB = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; // loading nib (might contain more than one view)
MyCustomView* problemView = allTheViewsInMyNIB[0]; // getting desired view
problemView.frame = CGRectMake(0,0,100,100); //setting the frame
[self.view addSubview:problemView]; // showing it to user

That's all you have to do, to present a view. If you want to interact with this view you have to declare MyCustomView* problemView in your class' interface, not in the method.

However, doesn't that break encapsulation? Shouldn't the only entity that cares about the nib name be the UIView itself? As per: blog.bignerdranch.com/

Also, why does this need to be in -[viewDidAppear:]? Why can't you instantiate in -[viewDidLoad] so long as you're not doing any layout?

You can do it whereever you want, I've used viewDidLoad as an example to help KenHaggerty get an idea of how it works. Now the code is working, he can modify it accordingly to his needs.

I tried using it in -[viewDidLoad] and I once again got an empty view.

ios - Subviews for custom UIView with Nib (.xib) don't load? - Stack O...

ios objective-c uiview xib nib
Rectangle 27 29

The didLoad function lets you put all your custom initialization code. As others have mentioned, didLoad will be called when a view is created programmatically via init(frame:) or when the XIB deserializer merges a XIB template into your view via init(coder:)

Aside: layoutSubviews and updateConstraints are called multiple times for the majority of views. This is intended for advanced multi-pass layouts and adjustments when a view's bounds changes. Personally, I avoid multi-pass layouts when possible because they burn CPU cycles and make everything a headache. Additionally, I put constraint code in the initializers themselves as I rarely invalidate them.

import UIKit

class MyView: UIView {
  //-----------------------------------------------------------------------------------------------------
  //Constructors, Initializers, and UIView lifecycle
  //-----------------------------------------------------------------------------------------------------
  override init(frame: CGRect) {
      super.init(frame: frame)
      didLoad()
  }

  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    didLoad()
  }

  convenience init() {
    self.init(frame: CGRectZero)
  }

  func didLoad() {
    //Place your initialization code here

    //I actually create & place constraints in here, instead of in
    //updateConstraints
  }

  override func layoutSubviews() {
     super.layoutSubviews()

     //Custom manually positioning layout goes here (auto-layout pass has already run first pass)
  }

  override func updateConstraints() {
    super.updateConstraints()

    //Disable this if you are adding constraints manually
    //or you're going to have a 'bad time'
    //self.translatesAutoresizingMaskIntoConstraints = false

    //Add custom constraint code here
  }
}

Can you explain when/why you would split up layout constraint code between a method called from your init process and layoutSubviews and updateConstraints? It seems like they are all three possible candidate locations to place layout code. So how do you know when/what/why to split up layout code between the three?

I never use updateConstraints; updateConstraints can be nice because you know your view hierarchy was set up fully in init, so you can't raise an exception by adding a constraint between two views not in the hierarchy :) layoutSubviews should never have constraint modifications; it can easily cause an infinite recursion as layoutSubviews is called if constraints are 'invalidated' during the layout pass. Manual layout setup (as in setting frames directly, which you rarely need to do anymore unless for performance reasons) goes in layoutSubviews. Personally, I place constraints creation in init

ios - Proper practice for subclassing UIView? - Stack Overflow

ios objective-c cocoa-touch uiview
Rectangle 27 26

The didLoad function lets you put all your custom initialization code. As others have mentioned, didLoad will be called when a view is created programmatically via init(frame:) or when the XIB deserializer merges a XIB template into your view via init(coder:)

Aside: layoutSubviews and updateConstraints are called multiple times for the majority of views. This is intended for advanced multi-pass layouts and adjustments when a view's bounds changes. Personally, I avoid multi-pass layouts when possible because they burn CPU cycles and make everything a headache. Additionally, I put constraint code in the initializers themselves as I rarely invalidate them.

import UIKit

class MyView: UIView {
  //-----------------------------------------------------------------------------------------------------
  //Constructors, Initializers, and UIView lifecycle
  //-----------------------------------------------------------------------------------------------------
  override init(frame: CGRect) {
      super.init(frame: frame)
      didLoad()
  }

  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    didLoad()
  }

  convenience init() {
    self.init(frame: CGRectZero)
  }

  func didLoad() {
    //Place your initialization code here

    //I actually create & place constraints in here, instead of in
    //updateConstraints
  }

  override func layoutSubviews() {
     super.layoutSubviews()

     //Custom manually positioning layout goes here (auto-layout pass has already run first pass)
  }

  override func updateConstraints() {
    super.updateConstraints()

    //Disable this if you are adding constraints manually
    //or you're going to have a 'bad time'
    //self.translatesAutoresizingMaskIntoConstraints = false

    //Add custom constraint code here
  }
}

Can you explain when/why you would split up layout constraint code between a method called from your init process and layoutSubviews and updateConstraints? It seems like they are all three possible candidate locations to place layout code. So how do you know when/what/why to split up layout code between the three?

I never use updateConstraints; updateConstraints can be nice because you know your view hierarchy was set up fully in init, so you can't raise an exception by adding a constraint between two views not in the hierarchy :) layoutSubviews should never have constraint modifications; it can easily cause an infinite recursion as layoutSubviews is called if constraints are 'invalidated' during the layout pass. Manual layout setup (as in setting frames directly, which you rarely need to do anymore unless for performance reasons) goes in layoutSubviews. Personally, I place constraints creation in init

ios - Proper practice for subclassing UIView? - Stack Overflow

ios objective-c cocoa-touch uiview
Rectangle 27 24

You're almost there. You need to override initWithCoder in your custom class you assigned the view to.

- (id)initWithCoder:(NSCoder *)aDecoder {
    if ((self = [super initWithCoder:aDecoder])) {
        [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"ViewYouCreated" owner:self options:nil] objectAtIndex:0]];
    }
    return self; }

Once that's done the StoryBoard will know to load the xib inside that UIView.

UIViewController

The blue space is basically a UIView that will "hold" your xib.

and this is the final result:

The difference between the first clickMe and the second is that the first was added to the UIViewController using the StoryBoard. The second was added using code.

I don't know if it would work, but couldn't you add the view in layoutSubviews instead of initWithCoder: and make the class IB_DESIGNABLE? I guess it would depend on if IB_DESIGNABLE classes are capable of loading from the bundle

I don't know if I misapplied your answer, but it didn't work as expected. In one case, I placed it in the ProgramProgressControl class that the .xib has registered as a file owner. In that case, it threw an exception at the super send. In the other, I placed it in my table cell subclass, where this is to be placed. The views kind of showed up, but were not even inside of the shell, and I didn't appear to be hooked up to the outlets.

I'm not sure how your code works but I've found a full example for you that demonstrates how initWithCoder and a xib file works. stackoverflow.com/questions/9251202/

Or, instead of overriding initWithCoder, you can override awakeAfterUsingCoder: and do an actual view swap. Same amount of work, better result.

ios - How to embed a custom view xib in a storyboard scene? - Stack Ov...

ios objective-c xcode interface-builder uistoryboard
Rectangle 27 20

You reassigned your custom view's class to the view that lived in your xib. You don't need to do that because then what you got back was the view from the xib and you've just leaked your CoverPanel. So, simply replace your initializer:

- (id)initWithFrame:(CGRect)frame 
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // No need to re-assign self here... owner:self is all you need to get
        // your outlet wired up...
        UIView* xibView = [[[NSBundle mainBundle] loadNibNamed:@"CoverPanel" owner:self options:nil] objectAtIndex:0];
        // now add the view to ourselves...
        [xibView setFrame:[self bounds]];
        [self addSubview:xibView]; // we automatically retain this with -addSubview:
    }
    return self;
}

Oh of course, that makes perfect sense. It works now, thanks!

iphone - Loading UIView from xib, crashes when trying to access IBOutl...

iphone xcode uiview nib
Rectangle 27 2

After some digging I found a workaround. Basically instead of linking my IBOutlets and IBActions to the file's owner I linked them directly to the root view's class (which has the IB-properties exposed via the custom subclass).

The key was to just not rely on the file's owner and instead connect outlets and actions directly to the custom view.

- (instancetype)initFromNib {
    return [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil] firstObject];
}

I've create a category on UIView for initializing views from XIBs (it assumes the XIB name is the same as the class name).

#import <UIKit/UIKit.h>

@interface UIView (Initialization)

- (instancetype)initFromNib;

@end
#import "UIView+Initialization.h"

@implementation UIView (Initialization)

- (instancetype)initFromNib {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:nil options:nil] firstObject];
}

@end

You can then simply do:

MyView *myView = [[MyView alloc] initFromNib];

Assuming you have a MyView.xib file with a root view who's class is MyView.

this does not work for me when I set the file owner of the Xib in IB to the CustomClass. Instead, one is supposed to set the view to the custom class in the xib and that's it I believe.

ios - Instantiating a UIView from a XIB file with itself as the file's...

ios uiview interface-builder xib
Rectangle 27 8

CustomCell *cell = (CustomCell*)[tableView    dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
    // Load the top-level objects from the custom cell XIB.
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
    cell = [topLevelObjects objectAtIndex:0];
}

@TheDoctor I follow creating customCell with xib @ weheartswift.com/swifting-around. In this tutorial he don't implement func ... heightForRowAtIndexPath. But my cells are overlapping if I don't use this function. what's wrong with my code ?

@EmAdpres: The default height of a cell is 44, if your custom cell is of different height you need to either implement heightForRowAtIndexPath or set cell height for the tableview in interface builder.

@TheDoctor I set cell height for the tableview in interface builder and still it overlapping. I think I have no other choice than implementing heightForRowAtIndexPath as my list is not static according to this answer. Am I right or I have still chance to set cell height in interface builder ?

heightForRowAtIndexPath is used for dynamically changing the height of cell at runtime. If you want the cells in the tableView to be of different height you must implement this method.

iphone - Design a UIView as the tableview cell with separate xib file ...

iphone ios ios5 ios4 ios6