EzDevInfo.com

interface-builder interview questions

Top interface-builder frequently asked interview questions

how do I use UIScrollView in Interface Builder?

While I've used UIScrollView successfully in the past by manipulating it programmatically, I'm having trouble getting it to work by setting it up exclusively in Interface Builder.

I have a simple "about" page in my iPhone app. It has a UITextView, some icons, and links to my other apps. I have added all of these views to my UIScrollView, arranging them so that their total size is > 480. When I launch my app, the scrollview displays only the contents that fit on the screen, and nothing scrolls.

Is it possible to do this entirely via IB, or must I manipulate the contentSize via code?


Source: (StackOverflow)

Can't resize UIView in IB

Probably something simple, but I can't figure why I cannot resize a UIView in a xib in Interface Builder.

I created a new view XIB in xcode and in the size inspector, the width and height are disabled and grayed out to 320 by 460. This is strange since I can change the size for the other two views (associated with the other two tab bar items).

I am not sure if this has anything to do with but I recently updated the sdk to 3.

Thanks!


Source: (StackOverflow)

Advertisements

IBOutlet and IBAction

What is the purpose of using IBAction and IBOutlet in Objective-C coding for the iPhone, does it make any difference if I don't use them?


Source: (StackOverflow)

Remove autolayout (constraints) in Interface Builder

I'm trying to make my project compatible with Snow Leopard and I am not able to remove the autolayout in the nibs using Interface builder (XCode 4.3 on Lion).

Is it possible to remove the constraints and the autolayout in a nib on XCode?


Source: (StackOverflow)

How to add a button to UINavigationBar?

How to add a button to UINavigationBar programmatically?


Source: (StackOverflow)

Loading a Reusable UITableViewCell from a Nib

I am able to design custom UITableViewCells and load them just fine using the technique described in the thread found at http://forums.macrumors.com/showthread.php?t=545061. However, using that method no longer allows you to init the cell with a reuseIdentifier which means you have to create whole new instances of each cell at every call. Has anyone figured out a good way to still cache particular cell types for reuses, but still be able to design them in Interface Builder?


Source: (StackOverflow)

How do I enter RGB values into Interface Builder?

How can I enter RGB or Hex color values for backgrounds in Interface Builder? I can select predefined colors but I would like to manually enter in RGB values. Where can I do this?


Source: (StackOverflow)

Programmatically send to front/back elements created from interface builder

In interface builder, there are layouts options to send to back or send to front any elements such as UIButton, UIImage, UILabel etc...

Now, I would like to do the same at runtime, programmatically.

Is there an easy way to do that?

I do not want to create different views, just play with the z-axis.

Thank you.

Yohann


Source: (StackOverflow)

Does anyone know what the new Exit icon is used for when editing storyboards using Xcode 4.5?

Right-clicking the Exit icon yields an empty window. Can't Ctrl-drag a connection to any IB elements or corresponding source files. Docs give no love. Doesn't appear in nib files, only storyboards. My assumption is that it's a corollary to segues, but I don't see any new methods to back it up. Anyone?


Source: (StackOverflow)

Loaded nib but the view outlet was not set - new to InterfaceBuilder

I added a new nib file to my project, and all I want to do is have it display on the screen for now.

However, when I click on the toolbar icon that is supposed to take me to the view that I created, I get an NSInternalInconsistencyException with the message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "..." nib but the view outlet was not set.'

So I opened up my nib file, and I see for the view that there are no referencing outlets set. However, I try to click and drag the circle for "new referencing outlet" to File Owner, but it won't let me...what do I need to do to get my view to display?

Thanks.


Source: (StackOverflow)

Should IBOutlets be strong or weak under ARC?

I am developing exclusively for iOS 5 using ARC. Should IBOutlets to UIViews (and subclasses) be strong or weak?

The following:

@property (nonatomic, weak) IBOutlet UIButton *button;

Would get rid of all of this:

- (void)viewDidUnload
{
    // ...
    self.button = nil;
    // ...
}

Are there any problems doing this? The templates are using strong as are the automatically generated properties created when connecting directly to the header from the 'Interface Builder' editor, but why? The UIViewController already has a strong reference to its view which retains its subviews.


Source: (StackOverflow)

"Unknown class in Interface Builder file" error at runtime

Even though Interface Builder is aware of a MyClass, I get an error when starting the application.

This happens when MyClass is part of a library, and does not happen if I compile the class directly in the application target.


Source: (StackOverflow)

Cocoa Touch: How To Change UIView's Border Color And Thickness?

I saw in the inspector that I can change the background color, but I'd like to also change the border color and thickness, is this possible?

Thanks


Source: (StackOverflow)

How to load a UIView using a nib file created with Interface Builder

I'm trying to do something a bit elaborate, but something that should be possible. So here is a challenge for all you experts out there (this forum is a pack of a lot of you guys :) ).

I'm creating a Questionnaire "component", which I want to load on a NavigationContoller (my QuestionManagerViewController). The "component" is an "empty" UIViewController, which can load different views depending on the question that needs to be answered.

The way I'm doing it is:

  1. Create Question1View object as a UIView subclass, defining some IBOutlets.
  2. Create (using Interface Builder) the Question1View.xib (HERE IS WHERE MY PROBLEM PROBABLY IS). I set both the UIViewController and the UIView to be of class Question1View.
  3. I link the outlets with the view's component (using IB).
  4. I override the initWithNib of my QuestionManagerViewController to look like this:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        if (self = [super initWithNibName:@"Question1View" bundle:nibBundleOrNil]) {
            // Custom initialization
        }
        return self;
    }
    

When I run the code, I'm getting this error:

2009-05-14 15:05:37.152 iMobiDines[17148:20b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "Question1View" nib but the view outlet was not set.'

I'm sure there is a way to load the view using the nib file, without needing to create a viewController class.


Source: (StackOverflow)

How to use auto-layout to move other views when a view is hidden?

I have designed my custom Cell in IB, subclassed it and connected my outlets to my custom class. I have three subviews in cell content which are: UIView (cdView) and two labels (titleLabel and emailLabel). Depending on data available for each row, sometimes I want to have UIView and two labels displayed in my cell and sometimes only two labels. What I am trying to do is to set constraints that way if I set UIView property to hidden or I will remove it from superview the two labels will move to the left. I tried to set UIView leading constraint to Superview (Cell content) for 10px and UILabels leading Constraints for 10 px to the next view (UIView). Later in my code

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(IndexPath *)indexPath {
...
Record *record = [self.records objectAtIndex:indexPath.row];

if ([record.imageURL is equalToString:@""]) {
     cell.cdView.hidden = YES;
}

I am hiding my cell.cdView and I would like the labels to move to the left however they are staying in the same position in Cell. I tried to remove cell.cdView from superview but it didn't work either. I have attached image to clarify what I am about.

cell

I know how to do this programatically and I am not looking for that solution. What I want is to set constraints in IB and I expect that my subviews will move dynamically if other views are removed or hidden. Is it possible to do this in IB with auto-layout?

.....

Source: (StackOverflow)