XIB doesn't load... just shows a black screen - iphone

I'm creating a universal application in iOS 4.2 and above.
I have a nib called DataInputViewController_iPhone.xib. On the first view controller which comes up I have a button which should launch the class DataInputViewController. It does it, but it doesn't show the contents of the XIB file. It just shows a black screen.
Any ideas why this happens?
I have this code which calls the new view controller:
-(IBAction)clickedButton:(id)sender {
if((UIButton *)sender == (UIButton *)startButton){
NSString *nibName;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
nibName = #"DataInputViewController_iPhone";
} else {
nibName = #"DataInputViewController_iPad";
}
DataInputViewController *nextVC = [[DataInputViewController alloc] initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:nextVC animated:YES];
}
else if((UIButton *)sender == (UIButton *)otherButton){
NSLog(#"clicked the other button");
}
}
NSLogging in this method and in the init method of the new view controller tells me that the nibNameOrNil variable is pulled through correctly.
This is what the (standard) init method looks like in DataInputViewController.m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
Any ideas why this is happening? Or how to fix?
Thanks :)

You don't have to manually set up the nib name. Just name them DataInputViewController~iphone.xib and DataInputViewController~ipad.xib, then call [[DataInputViewController alloc] init].
See iOS Supports Device-Specific Resources for more information.

I had the same problem. Just clean your project, close XCode, reboot your Mac and open project again.
And don't forget delete app on simulator or device previously.

The only way I have found to fix this is to delete the nibs and class and then recreate them. Not particularly elegant, but it works ...

I had this same issue where I needed to load either iPad or iPhone .xib files for a utility view controller. It is a form so it had a lot of UILabel and UITextField elements that were linked as IBOutlets. I would construct the entire layout, link all of the elements, and it worked fine until when I built and ran it. I even took the advice posted on this thread and re-created both .xib's and the class files (a great deal of linking IBOutlets) with no success.
The problem was this. The root view cannot be #synthesized in the implementation of the class. As soon as I synthesized the base view, everything went black. By simply removing the "#synthesize view;" line, everything worked like a charm. When I presented my view controller everything was there again.
Here is the header file for the class with all of the IBOutlets:
#import <UIKit/UIKit.h>
#interface SignUpFormViewController : UIViewController <UITextFieldDelegate, NSXMLParserDelegate>
#property (strong, nonatomic) IBOutlet UIView *rootView;
#property (weak, nonatomic) IBOutlet UILabel *signUpFormLabel;
#property (weak, nonatomic) IBOutlet UIButton *infoButton;
#property (weak, nonatomic) IBOutlet UILabel *enterEmailLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterEmailTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterPasswordLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterPasswordTextField;
#property (weak, nonatomic) IBOutlet UILabel *reEnterPasswordLabel;
#property (weak, nonatomic) IBOutlet UITextField *reEnterPasswordTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterFirstNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterFirstNameTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterLastNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterLastNameTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterPhoneNumberLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterPhoneNumberTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStreetAddressLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterStreetAddressTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStreetAddress2Label;
#property (weak, nonatomic) IBOutlet UITextField *enterStreetAddress2TextField;
#property (weak, nonatomic) IBOutlet UILabel *enterCityLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterCityTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStateLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterStateTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterZipLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterZipTextField;
#property (weak, nonatomic) IBOutlet UIButton *backButton;
#property (weak, nonatomic) IBOutlet UIButton *signUpNowButton;
- (IBAction)infoButtonPressed:(id)sender;
- (IBAction)backButtonPressed:(id)sender;
- (IBAction)signUpNowButtonPressed:(id)sender;
#end
Here is the implementation file with the root view being synthesized:
#import "SignUpFormViewController.h"
#implementation SignUpFormViewController
#synthesize rootView,signUpFormLabel,infoButton,enterEmailLabel,enterEmailTextField,enterPasswordLabel,enterPasswordTextField,reEnterPasswordLabel,reEnterPasswordTextField,enterFirstNameLabel,enterFirstNameTextField,enterLastNameLabel,enterLastNameTextField,enterPhoneNumberLabel,enterPhoneNumberTextField,enterStreetAddressLabel,enterStreetAddressTextField,enterStreetAddress2Label,enterStreetAddress2TextField,enterCityLabel,enterCityTextField,enterStateLabel,enterStateTextField,enterZipLabel,enterZipTextField,backButton,signUpNowButton,btnDone,btnPrev,btnNext,inputAccView,activeTextField,currentString;
Simply remove the "rootView" from the list of properties being synthesized and this should fix the problem. Much easier than deleting the .xib files for BOTH iPad and iPhone layouts and re-creating them.
FYI I am using xCode 4.6.3 with target SDK = 6.1
I hope this helps anybody else that experiences this time-consuming and very frustrating issue.

This may help you: delete your app on the simulator or device and run again. I find if I twiddle with nibs too much, especially around names or localization, it appears that everything works (I get no errors), but Xcode is actually ignoring the changes.
So perform a Clean (Product->Clean), delete from simulator or device, run again.

You have to make sure to implement the loadView method in your DataInputViewController.m and inside the method add the line [super loadView], like this:
- (void)loadView {
[super loadView];
}

I have found that not dragging an outlet from the File Owner to your custom sub-classed UITableViewCell.h or .m file can cause the blackness as well. Make sure that you drag an outlet to one of the two files associated with your sub-class of UITableViewCell.

In my case,
I was receive xib file from co-worker.
well loaded xib but did not shown.
spent all my one a day because Hidden checkbox was checked
check Hidden checkbox in xib.

Simple Fix!!
Navigating to version editor and back to standard editor fixed the problem for me

Related

uiscrollview in uiview not scrolling

I am using the storyboard to create a UIView that contains a UIScrollView that has many child items in it. these child items consist of a UIImageView that I am using as a background image for the UIScrollView, a series of UILabels that I populate programmatically, and a series of UITableViews that I populate with data obtained from a called set of library classes. I want all of this in my UIScrollView so the User can scroll through all of the information without having multiple views being displayed. I have browsed through a lot of postings here and have used a lot of the suggestions, but have been unable to successfully have the view scroll and allow the user to see all the data I'm attempting to present.
Here's a screen shot of the Storyboard followed by a shot of the attribute inspector for my UIScrollView
I'll also provide the .h and .m files
weatherController.h
#import <UIKit/UIKit.h>
#import "WeatherParser.h"
#import "WeatherLocation.h"
#import "WeatherImg.h"
#import "WeatherWind.h"
#import "ForcastDay.h"
#import "ForecastItem.h"
#import "Condition.h"
#import "Atmo.h"
#import "Astro.h"
#class WeatherParser;
#class WeatherParserDelegate;
#class WeatherLocation;
#class WeatherImg;
#class WeatherWind;
#class ForcastDay;
#class ForecastItem;
#class Condition;
#class Atmo;
#class Astro;
#interface weatherController : UIViewController <UITableViewDataSource,UITableViewDelegate,WeatherParserDelegate>{
WeatherParser * _rssParser;
bool loadingEvents;
}
#property (nonatomic, retain) WeatherParser * rssParser;
#property bool loadingEvents;
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UILabel *cityLabel;
#property (weak, nonatomic) IBOutlet UILabel *state_countryLabel;
#property (weak, nonatomic) IBOutlet UILabel *currHighLabel;
#property (weak, nonatomic) IBOutlet UILabel *currLowLabel;
#property (weak, nonatomic) IBOutlet UILabel *currTempLabel;
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UIImageView *logoImageView;
#property (weak, nonatomic) IBOutlet UILabel *logoLabel;
#property (weak, nonatomic) IBOutlet UITableView *forecastTableView;
#property (weak, nonatomic) IBOutlet UITableView *atmoTableView;
#property (weak, nonatomic) IBOutlet UITableView *windTableView;
#property (weak, nonatomic) IBOutlet UITableView *astroTableView;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (nonatomic, retain) NSMutableArray *forecastDays;
#property bool logoSet;
#end
and here's my weatherController.m file. I'm going to only add the viewDidLoad method which is the only method containing code regarding my UIScrollView.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_scrollView.delegate = self;
// self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 480.0F); //(320, 1210)];
[_scrollView setScrollEnabled:YES];
}
I would appreciate any help regarding what it is I'm either doing wrong or missing. If I set up my frame and contentSize to the following:
self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 1210.0F);
I do get the UIScrollView to scroll, but the image for the background is only the size of the frame, and none of the rest of the child content on the UIScrollView is displayed. It seems like it's allowing me to scroll but I'm only able to view the content that is viewable within the frame.
Again, thank you in advance for any help offered.
As the comments are suggesting, it's generally a bad idea to put a UITableView within a UIScrollView. I won't be too hard on you though, because there is a time and place where it is an acceptable solution. I'll let you judge if this time is now or not.
For reasons I still don't fully understand, UIScrollView behaves more like you expect it to if you enclose the entire contents in a single UIView that is as big as you want the UIScrollView to scroll.

how i can use more than one text fields in ios app design [duplicate]

This question already has answers here:
how i define and write many textfields properties in the header in ios [closed]
(4 answers)
Closed 9 years ago.
i add 4 text fields in the view and i cant find the way to write it in viewcontroller.h
i try this but not work
#interface ViewController : UIViewController
{
UITextField *TextField1 ;
UITextField *TextField2 ;
UITextField *TextField3 ;
UITextField *TextField4 ;
}
then a property doesnt work with me , like this :
{
#property (weak, nonatomic) IBOutlet UITextField *TextField1 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField2 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField3 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField4 ;
}
i need some help in that :(
Don't use braces for properties:
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *TextField1 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField2 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField3 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField4 ;
#end
Also, I hope you set up connections for the controls
Firstly you should do it like this, the proper way .
#interface ViewController : UIViewController
{
IBOutlet UITextField *TextField1 ;
IBOutlet UITextField *TextField2 ;
IBOutlet UITextField *TextField3 ;
IBOutlet UITextField *TextField4 ;
}
#property (weak, nonatomic) IBOutlet UITextField *TextField1 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField2 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField3 ;
#property (weak, nonatomic) IBOutlet UITextField *TextField4 ;
Well I think you are somewhere unclear about your concepts of the setter and getter methods and declaring simple variables inside an interface.
Please go through the following links :-
Difference between #interface declaration and #property declaration
Declaring IBOutlet inside or outside #interface?
Hope they help your understanding of these concepts more.

What is the owner of UI elements of a view controller? iOS5 with ARC

I am new to iOS 5. From Apple's documentation I know what ARC is and "Owner of an object should using strong notation." After read "Hello World" , I noticed a strange thing.(I mean that was confusing me)
HelloWorldAppDelegate:
#interface HelloWorldAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
HelloWorldViewController:
#import <UIKit/UIKit.h>
#interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)changeGreeting:(id)sender;
#property (copy, nonatomic) NSString *userName;
#end
Here:
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property (weak, nonatomic) IBOutlet UILabel *label;
UI elements have weak notation and none of file have a strong references to them. So I am confusing what/who hold them?
In my opinion you can consider the NIB/XIB as the owner of those objects. None of your classes own them. See "Managing the Lifetimes of Objects from Nib Files" in Resource Programming Guide:
From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File's Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong. Outlets that you create should will therefore typically be weak by default, because:
Outlets that you create to, for example, subviews of a view controller's view or a window controller's window, are arbitrary references between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example, UIViewController's view outlet, or NSWindowController's window outlet).

iPad/iPhone TableVIew help pushing a new view

So we have recently started developing applications for the iPad for our company. Unfortunately none of us here have ever done any iPhone/iPad development so we are just kind of learning on the fly and winging it. Basically our problem is happening when we try to push a view onto the screen when a table row is clicked. Neither of us can figure out why it's not doing it because the code looks 100% correct by anything we can tell. Here is what the didRowSelectedAtIndex: method looks like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if(pdvController == nil)
pdvController = [[PersonDetailViewController alloc] initWithNibName:#"PersonDetailView" bundle:[NSBundle mainBundle]];
Person *aPerson = [appDelegate.people objectAtIndex:indexPath.row];
pdvController.aPerson = aPerson;
[self.appDelegate.navigationController pushViewController:pdvController animated:YES];
}
and here is the header for the toolbarSearchViewController:
#import <UIKit/UIKit.h>
#import "RecentSearchesController.h"
#import "PersonDetailViewController.h"
#class ToolbarSearchAppDelegate, PersonDetailViewController;
#interface ToolbarSearchViewController : UIViewController <UISearchBarDelegate, UIPopoverControllerDelegate, RecentSearchesDelegate> {
ToolbarSearchAppDelegate *appDelegate;
UIToolbar *toolbar;
UISearchBar *searchBar;
UITableView *resultsTable;
PersonDetailViewController *pdvController;
RecentSearchesController *recentSearchesController;
UITableViewController *resultsTableController;
UIPopoverController *recentSearchesPopoverController;
}
#property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
#property (nonatomic, retain) UISearchBar *searchBar;
#property (nonatomic, retain) IBOutlet UITableView *resultsTable;
#property (nonatomic, retain) ToolbarSearchAppDelegate *appDelegate;
#property (nonatomic, retain) PersonDetailViewController *pdvController;
#property (nonatomic, retain) UITableViewController *resultsTableController;
#property (nonatomic, retain) RecentSearchesController *recentSearchesController;
#property (nonatomic, retain) UIPopoverController *recentSearchesPopoverController;
#end
and the ToolbarSearchAppDelegate header:
#import <UIKit/UIKit.h>
#class ToolbarSearchViewController;
#interface ToolbarSearchAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ToolbarSearchViewController *viewController;
UINavigationController *navigationController;
NSMutableArray *people;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ToolbarSearchViewController *viewController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#property (nonatomic, retain) NSMutableArray *people;
#end
and finally the personDetailController.h:
#import <UIKit/UIKit.h>
#class Person;
#interface PersonDetailViewController : UIViewController {
IBOutlet UITableView *tableView;
Person *aPerson;
}
#property (nonatomic, retain) Person *aPerson;
#property (nonatomic, retain) UITableView *tableView;
#end
We are getting pretty annoyed because neither of us can figure out why it's not loading and any help or insight you guys could provide would be amazing. I wasn't sure what you may need to see, so if you need anything more specific, let me know and I will post it. Thanks!
ps. I am not sure how the code tags are going to handle all of Obj-c's quirky syntax, so if you see syntax errors, just ignore them. Assume that it is syntactically correct and will compile and run...
This line looks a little odd:
[self.appDelegate.navigationController pushViewController:pdvController animated:YES];
try and make it
[self.navigationController pushViewController:pdvController animated:YES];
edit summing op, the problem is that you don't have a navigation controller, so you can't push a view controller like that. What you can do, is pushing a view controller modally, using
[self presentModalViewController:pdvController animated:YES];

Why doesn't IB see my IBAction?

I've been staring at this for way too long.
There's nothing fancy happening here, and I've done this dozens of times, yet Interface Builder steadfastly refuses to provide me an action target for -(IBAction)slideDirections. I'm at the point where I'm willing to post publicly and feel stupid. So let 'er rip.
Here's my .h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface PulseDetailController : UIViewController {
NSDictionary *pulse;
IBOutlet MKMapView *map;
IBOutlet UIWebView *directions;
IBOutlet UIView *directionsSlider;
BOOL directionsExtended;
IBOutlet UILabel *vendor;
IBOutlet UILabel *offer;
IBOutlet UILabel *offerText;
IBOutlet UILabel *hours;
IBOutlet UILabel *minutes;
IBOutlet UILabel *seconds;
IBOutlet UILabel *distance
}
#property (nonatomic, retain) NSDictionary *pulse;
#property (nonatomic, retain) MKMapView *map;
#property (nonatomic, retain) UIWebView *directions;
#property (nonatomic, retain) UIView *directionsSlider;
#property (nonatomic) BOOL directionsExtended;
#property (nonatomic, retain) UILabel *vendor;
#property (nonatomic, retain) UILabel *offer;
#property (nonatomic, retain) UILabel *offerText;
#property (nonatomic, retain) UILabel *hours;
#property (nonatomic, retain) UILabel *minutes;
#property (nonatomic, retain) UILabel *seconds;
#property (nonatomic, retain) UILabel *distance;
-(IBAction)slideDirections;
#end
Shouldn't the IBAction have a sender parameter?
Like:
-(IBAction)slideDirections:(id)sender;
Sometimes Interface Builder seems to get out of sync with classes in Xcode. Have you tried forcing interface builder to reread your PulseDetailController header file? (File -> Read Class Files... -> Select 'PulseDetailController.h'). This should force Interface Builder to see your new action.
Which objects are you trying to connect?
From your header, the logical choice would be UIView *directionsSlider
If you are ctrl dragging from directionsSlider to the "File's Owner" object, make sure that the Class in "File's Owner" is set to PulseDetailController.