3

Sorry for my bad english , and i am very new in ios development. i am trying to add a new IBOutlet for my TutorialChildController which is inherited from UIViewController. My TutorialChildController is in Storyboard and it has UILabel, UIButton, and UIImage. I am creating it dynamically in another ViewController which is rootViewController .The code is calling at viewDidLoad like this:

TutorialChildController *tutorialChildController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialChildController"];

here is my TutorialChildController.h :

#import <UIKit/UIKit.h>

@interface TutorialChildController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *startButton;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *tutorialImage;


@property  NSUInteger index;
@property NSString *titleText;
@property NSString *imageFile;

@end

however in TutorialChildController.m i am trying to check my Outlets but my startButton is null.

- (void)viewDidLoad
{
 [super viewDidLoad];
 NSLog(@"myButton : %@ ", self.startButton); // output is null
 NSLog(@"myLabel : %@ ", self.titleLabel); // output is object
}

all IBOutlets linked in storyboard and just startButton is null. I don't know why.

i added some screenshots:

ss1

ss2

ss3

Zifozi
  • 109
  • 10
  • check the storyboard, make sure startbutton is properly linked to your property. You can also know by going to TutorialChildController.h and checking if there is a filled dot on the left of the property, or if its an empty dot, empty means nothing is linked to it. – Pochi May 01 '14 at 00:50
  • thanks but it is a filled dot for startButton. Also checked again from stroyboard and its linked with property. – Zifozi May 01 '14 at 00:58
  • your view did load method should start with a [super viewDidLoad]; by the way, try adding ANOTHER button, and see if that one is null. (but dont change any of the button properties, just add it on the story board, and link it) – Pochi May 01 '14 at 01:00
  • Oh sorry, i forgot to add super in question. It is already defined. I updated my code. – Zifozi May 01 '14 at 01:02
  • i did your suggest and another button is null too :/ in .h file its filled dot too – Zifozi May 01 '14 at 01:06
  • Please read the 'Xcode Overview : Builder a user interface' section: Connect User Interface Objects to Code – Danyun Liu May 01 '14 at 02:01
  • I see a connected outlet called nextButton, but nowhere do I see anything in your screen shots about a startButton. Did you change the name at some point? – rdelmar May 01 '14 at 03:58
  • Yes i deleted my IBOutlet startButton and put a new linked IBOutlet named nextButton. But it does not work ... – Zifozi May 01 '14 at 10:59

4 Answers4

4

I cant believe , just tried on Xcode menu:

product > clean and it works now!!!! damn it.

that took me 7-8hrs to solve. :/ Thanks guys for helping.

Zifozi
  • 109
  • 10
1

Make sure that the button is connected as a Referencing Outlet to the view controller, not an Outlet Collection

1: enter image description here

mittens
  • 756
  • 6
  • 9
  • i already did. Also i have added screenshots of my project, you can check it. – Zifozi May 01 '14 at 02:19
  • I'm talking in reference to the button, its tied up correctly in regards to the view controller (mine looks the same) but when selecting the button from the list is it set correctly in the *Referencing Outlets* as well? – mittens May 01 '14 at 02:21
  • Yes, as i said it is connected like other Outlets and just i getting null for that button. – Zifozi May 01 '14 at 02:23
0

try this:

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  NSLog(@"myButton : %@ ", self.startButton.titleLabel.text);
  NSLog(@"myLabel : %@ ", self.titleLabel.text);
}
Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
  • self.startButton is null so titleLabel is null too – Zifozi May 01 '14 at 02:12
  • not sure where you are going wrong. Just post the whole project somewhere, easier to check why its not working – Nitin Alabur May 01 '14 at 02:13
  • Try to flesh out your answer a bit more. Just posting a code block without any explanation or context is not good. – Xaver Kapeller May 01 '14 at 02:15
  • i have added screenshots of my project, you can check it. – Zifozi May 01 '14 at 02:17
  • @XaverKapeller I'd rather help Zifozi find where the mistake is, than explain everything in one go. I had a hunch where Zifozi was wrong. I think its something way more simpler than that. – Nitin Alabur May 01 '14 at 02:25
  • @NitinAlabur Yeah I realize that but your answer was already flagged as low quality. I assume it was because of the lack of content in your answer. – Xaver Kapeller May 01 '14 at 02:29
0

1: Remove the button from storyboard and delete the line @property (weak, nonatomic) IBOutlet UIButton *startButton;

2: Add another button, make it strong just in case.

It should definitely work.

Zia
  • 14,622
  • 7
  • 40
  • 59
  • That is strange. You should post more code or just do it programatically. – Zia May 01 '14 at 01:42
  • here are screenshots of my some of code and IB http://imgur.com/twMc1tP http://imgur.com/h3mcrCV http://imgur.com/JI3QEtt – Zifozi May 01 '14 at 01:59