myApp[12345:678] Could not load the "image.png" image referenced from a nib in the bundle with identifier "com.company.app"
Showing posts with label interface builder. Show all posts
Showing posts with label interface builder. Show all posts
Tuesday, February 28, 2012
Could not load the image referenced from a nib in the bundle with identifier
Just make sure your files are where you (your project file) thinks they are.
Check for filenames in red (at left), indicating that somehow some file became unknown. Maybe you were moving files around in Finder, were you? Of course you were, you silly bugger!
Wednesday, April 20, 2011
How to Change UIView Size in Interface Builder
When you create a new UIView XIB in Interface Builder, it is by default full-screen. Width and height cannot be changed, they are dimmed out. What to do?
Switch to Simulated Metrics and change "Status Bar" from default (gray) to None. Now you can edit the size!
First time this was difficult to discover, second time I kind of recalled what to do and now it's all so plain obvious :)
Switch to Simulated Metrics and change "Status Bar" from default (gray) to None. Now you can edit the size!
First time this was difficult to discover, second time I kind of recalled what to do and now it's all so plain obvious :)
Monday, April 18, 2011
Operation failed with underlying error 4294956467
Thanx Xcode, that was very informative. I'll fix it right away! Oh wait, what was that...
Failed to launch simulator: Operation failed with underlying error 4294956467.
Thursday, November 11, 2010
How to Define UITableViewCell reuseIdentifier for loadNibNamed
When you create UITableViewCells, it's important to use reuseIdentified. This lets iOS recycle your table cells, thus improving performance and minimizing memory use. Using it is pretty simple:
Warning: you should NEVER access objects inside XIB (NIB) by magical index into array! Apple might change "something" in next Xcode release and thus break your code. You should use IBOutlets. You have been warned.
...yes, this is one of those sad "don't do as I do, but as I tell you to" cases...
static NSString *idCell = @"MyCellId";Try to reuse an already existing, but not currently used, cell created earlier with given identifier "MyCellId". If such isn't found, create a new one:
cell = (UITableViewCell *)[aTableView dequeueReusableCellWithIdentifier:idCell];
if (cell == nil)This code requires a separate stand-alone XIB, which contains nothing but your UITableViewCell. But how do you define the reuseIdenfier? That property is read-only and created when table cell is created.
{
static NSString *nibcell = @"MyCell";
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibCell owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}
reuseIdentifierOpen your XIB in Interface Builder, select UITableViewCell object, open "Table View Cell Attributes" (press command-1) and write your hardcoded magical string "MyCellId" into "Identifier" field. Use the same string in your code as reuseIdentifier.
A string used to identify a cell that is reusable. (read-only)
@property(nonatomic, readonly, copy) NSString *reuseIdentifier
Warning: you should NEVER access objects inside XIB (NIB) by magical index into array! Apple might change "something" in next Xcode release and thus break your code. You should use IBOutlets. You have been warned.
...yes, this is one of those sad "don't do as I do, but as I tell you to" cases...
Labels:
dequeueReusableCellWithIdentifier,
IBOutlet,
interface builder,
iphone,
loadNibNamed,
mainBundle,
NSBundle,
NSString,
objectAtIndex,
reuseIdentifier,
UITableViewCell,
XIB
Thursday, October 14, 2010
How to Control UISearchBar Background Color
When you have a list, you want to search it. How would you do that? No, don't code it by yourself. Done it, removed it.
By default each UITableView comes with search support via a built-in UISearchDisplayController. You just add and connect UISearchBar to your table in Interface Builder and provide some delegate methods to make it work. Pretty easy:
You can fix that by doing two things. First get rid of default background:
Sad to think how many hours I wasted experimenting Things That Will Not Work, just to find out that kind of miniscule solution. Also bet that this will not work one year from now...
By default each UITableView comes with search support via a built-in UISearchDisplayController. You just add and connect UISearchBar to your table in Interface Builder and provide some delegate methods to make it work. Pretty easy:
self.searchDisplayController.delegate =Controlling how your UISearchBar looks like is a bit more difficult. If you want to show search box and some other component(s) side by side, you can do it by putting UIToolbar at back and a short UISearchBar on top of it. By default their backgrounds are different, looking pretty ugly together. Like a hack, what it really is.
self.searchDisplayController.searchBar.delegate =
self.searchDisplayController.searchResultsDataSource =
self.searchDisplayController.searchResultsDelegate = self.mySearchObject;
You can fix that by doing two things. First get rid of default background:
for (UIView *view in self.searchBar.subviews)...and the second thing? Something that will be extremely hard to find out, unless you get it right by accident? You have to set UISearchBar style Black Translucent!
{
if ([view isKindOfClass:NSClassFromString
(@"UISearchBarBackground")])
{
[view removeFromSuperview];
break;
}
}
Sad to think how many hours I wasted experimenting Things That Will Not Work, just to find out that kind of miniscule solution. Also bet that this will not work one year from now...
Labels:
delegate,
interface builder,
isKindOfClass,
NSClassFromString,
UISearchBarBackground,
UISearchDisplayController,
UITableView,
UIToolbar,
UIView
Thursday, October 7, 2010
How to Get Rid of Keyboard with a Tap on Background part2
There was a nice way to remove keyboard by using UITextView, but that has stopped working with iOS4. At least I got such a defect report for beta application. This time I will remove keyboard using UIButton, let's see how long that will work:
Nice, easy, simple, fast - what more can you ask for!
- (IBAction)removeKeyboardOpen your view in Interface Builder, create new custom full screen UIButton to cover everything, select UITextFields and UIButtons (etc.) one by one and "Send to Front" via Layout menu. Connect UIButton "Touch Up Inside" to your callback and that's it.
{
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
}
Nice, easy, simple, fast - what more can you ask for!
Labels:
interface builder,
iOS4,
iphone,
keyboard,
touch,
UIButton,
UITextField,
UITextView
Wednesday, October 6, 2010
How to Float an Icon after UILabel
Want to place a floating icon right after a variable lenght text string - using Interface Builder? Wonderful helper that IB tool or so I thought...
First create a UITableViewCell template with IB, put there a fixed lenght UILabel followed by a UIImageView. No problems, their values are easy to setup at cellForRowAtIndexPath with view tag id numbers:
I had a problem that Interface Builder wanted to set UITableViewCell tag same as my image tag. No errors, no warnings, no indications of problem - except that I couldn't get my image frame no matter how much I banged head into brickwall! Removing tag didn't help, it just automagically came back. Ouch!
First create a UITableViewCell template with IB, put there a fixed lenght UILabel followed by a UIImageView. No problems, their values are easy to setup at cellForRowAtIndexPath with view tag id numbers:
UILabel *label = nil;But how to "float" that image right after text string? UILabel is fixed sized, so that won't help. Have to check the size of label.text instead:
UIImageView *image = nil;
CGRect frame;
// Title
label = (UILabel *)[cell viewWithTag:1];
label.text = @"Title text";
// IconThat's it, very simple! Just beware that your tag numbers MUST be unique.
image = (UIImageView *)[cell viewWithTag:10];
image.image = [UIImage imageNamed:@"logo.png"];
// Icon positioning
frame = image.frame;
CGSize f = [label sizeThatFits:label.frame.size];
frame.origin.x = label.frame.origin.x + f.width + 4;
image.frame = frame;
I had a problem that Interface Builder wanted to set UITableViewCell tag same as my image tag. No errors, no warnings, no indications of problem - except that I couldn't get my image frame no matter how much I banged head into brickwall! Removing tag didn't help, it just automagically came back. Ouch!
Labels:
CGRect,
imageNames,
interface builder,
iphone,
sizeThatFits,
UIImage,
UIImageView,
UILabel,
UITableViewCell
Tuesday, September 21, 2010
<Error>: CGImageCreateWithImageProvider: invalid image size: 0 x 0
There seems to be a bug in iOS 4.0 built-in MapKit, which causes error message in both simulator and real device:
Warning disappears and I'm back on Zero Warning policy!
<Error>: CGImageCreateWithImageProvider: invalid image size: 0 x 0.This happens when I open UIViewController, which contains MKMapView (all created with Interface Builder). Since user location is not needed at this moment, I just unchecked "Shows User Location" checkbox on Map View Attributes.
Warning disappears and I'm back on Zero Warning policy!
Labels:
interface builder,
iOS4,
map,
MKMapViewDelegate,
UIViewController
Thursday, April 29, 2010
Multiline UIButton Title
Some things are really easy with iPhone SDK - eventually. For example if you want to have a non-custom UIButton with multiline title:
Write button title in "Title" field. When you want to have a linebreak, press Alt-Return. Then set "Line Breaks" as Character Wrap or Word Wrap. Done!
(Using Interface Builder)
Write button title in "Title" field. When you want to have a linebreak, press Alt-Return. Then set "Line Breaks" as Character Wrap or Word Wrap. Done!
(Using Interface Builder)
Monday, April 26, 2010
How to Get Rid of Keyboard with a Tap on Background
There is a screen with a couple of UITextFields and UIButtons. When user taps on UITextField, keyboard popups. Very nice of iPhone SDK to provide such a feature! Each UITextField and UIButton is a clickable object with easy callbacks.
But how do you get rid of keyboard?
Should you have a special "Please hide keyboard" button or tap into accelerometer to notice when user gets desperate enough to start shaking the device? There's an easier way...
Add a full-screen empty non-editable UITextView over the whole screen. Select each clickable object e.g. UITextField, UIButton or other UITextViews and use Interface Builder menu item Layout - Send to Front to place them on top of your full-screen UITextField.
When user clicks on anywhere except your clickable objects, keyboard disappears. What a relief!
Please note that, if you leave any non-clickable objects e.g. UILabel on top of your full-screen UITextView, clicking on those spots will not hide keyboard.
But how do you get rid of keyboard?
Should you have a special "Please hide keyboard" button or tap into accelerometer to notice when user gets desperate enough to start shaking the device? There's an easier way...
Add a full-screen empty non-editable UITextView over the whole screen. Select each clickable object e.g. UITextField, UIButton or other UITextViews and use Interface Builder menu item Layout - Send to Front to place them on top of your full-screen UITextField.
When user clicks on anywhere except your clickable objects, keyboard disappears. What a relief!
Please note that, if you leave any non-clickable objects e.g. UILabel on top of your full-screen UITextView, clicking on those spots will not hide keyboard.
Labels:
accelerometer,
interface builder,
iphone,
keyboard,
touch,
UIButton,
UILabel,
UITextField,
UITextView
Friday, April 23, 2010
UITableView doesn't scroll
This makes no sense, but seems like (in Interface Builder) your UITableView must have Scroll View section item Delay Content Touches checked.
Otherwise your table doesn't scroll by touch events.
Otherwise your table doesn't scroll by touch events.
Tuesday, March 16, 2010
Changing Name of "Edit" UIBarButtonItem
If you use default UIToolbar "Edit" button provided by Interface Builder, you cannot change the name from code. You have to change UIBarButtonItem identifier to "Custom" and title as "Edit". Then add this delegate code:
Don't forget to hardcode button width at 43 pixels, otherwise change of button title will shift position of following items on toolbar. That 43 pixels is the default width of standard Edit button and wide enough to show longer "Done" text string.- (IBAction)setEditing:(BOOL)editing animated:(BOOL)animated { [self.myController.myView setEditing: !self.myController.myView.editing animated:YES]; if (self.myController.myView.editing) { self.editButton.title = @"Done"; self.editButton.style = UIBarButtonItemStyleDone; } else { self.editButton.title = @"Edit"; self.editButton.style = UIBarButtonItemStyleBordered; } }
Labels:
interface builder,
iphone,
UIBarButtonItem,
UIToolbar
Monday, March 15, 2010
Interface Builder cannot change UIView color
If you fail to change UIView color in Interface Builder, it could be because Emulator is blocking your changes. Close emulator and try again.
Monday, March 1, 2010
How to Create a Black Statusbar
When you open MainWindow.xib in Interface Builder, you can find "Window - Status Bar" and "MainViewController - Status Bar". Setting either one or both as "Black" doesn't seem to have any effect on the actual application. Your statusbar remains gray.
So how do I get a black statusbar?
Open your application .plist file, click on plus icon (+) to create a new row and write "Status bar style" as name and select "Opaque black style" as value.
Those are "key = UIStatusBarStyle" and "string = UIStatusBarStyleOpaqueBlack if you're more familiar with that style.
So how do I get a black statusbar?
Open your application .plist file, click on plus icon (+) to create a new row and write "Status bar style" as name and select "Opaque black style" as value.
Those are "key = UIStatusBarStyle" and "string = UIStatusBarStyleOpaqueBlack if you're more familiar with that style.
Labels:
interface builder,
iphone,
plist,
UIStatusBarStyle,
XIB
Tuesday, February 16, 2010
Why viewWillAppear Wasn't Called?
Have several views defined as XIB, work just fine as standalone views and as main views under UITabBar. However they stopped working when added them as subviews under main view in UITabBar (don't ask...)
The problem was that viewWillAppear wasn't called automatically, because I added the views manually under another view. Apple documentation suggests calling the missing function manually - and yet again everything works just fine!
The problem was that viewWillAppear wasn't called automatically, because I added the views manually under another view. Apple documentation suggests calling the missing function manually - and yet again everything works just fine!
self.myController =
[[MyViewController alloc]
initWithNibName:@"MyViewController" bundle:nil];
[self.mainView addSubview:myController.view];
[self.myController viewWillAppear:YES];
Labels:
interface builder,
iphone,
UITabBar,
viewWillAppear,
XIB
Wednesday, January 27, 2010
How to Scroll TextField visible Under Keyboard
Very thorough keyboard handling tutorial "iPhone Programming - Editing TextFields without Obscuring Them" by Steve at act_as_geek blog. Lots of pictures, very patiently walking through how to setup things in Interface Builder!
Wonder how it behaves when you have UITableView somewhere.
Currently I use UIControl as root which contains UINavigationBar, UITableView, UIView and UIButton. When keyboard appears, I got to scroll... well, everything visible. Basically I do what is done in that tutorial, but without UIScrollView. Resize one table and one view. Messy.
Time to refactor. Will try how that sample works.
Wonder how it behaves when you have UITableView somewhere.
Currently I use UIControl as root which contains UINavigationBar, UITableView, UIView and UIButton. When keyboard appears, I got to scroll... well, everything visible. Basically I do what is done in that tutorial, but without UIScrollView. Resize one table and one view. Messy.
Time to refactor. Will try how that sample works.
Labels:
interface builder,
iphone,
keyboard,
tutorial,
UIScrollView,
UITableView
Subscribe to:
Posts (Atom)