button not displaying in simulator - ios

Edit re-wrote question:
Hi there I'm working on another student's project (taking over) there's no main storyboard, only a viewonctroller.Xib under resources a Viewcontroller.h and .m
I'm trying to add new buttons but they aren't displaying. I linked the new buttons to the viewcontroller.h and .m file with no actual code in the code such as
-(IBAction)button { empty }
in the .h file it's
IBOutlet UIButton *button;
The button's not displaying in the simulator however, Also the former student has every button in the app displayed in the same window and just uses the setHidden function to distinguish between menu's in game. I thought that maybe the button was just behind other buttons but when I go to editor-> send to front the option is grayed out.
edit Sample code of ViewController.H
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
// Game Center -- ignore and or delete
#import <GameKit/GameKit.h>
#import "GameCenterManager.h"
#interface SideWinderViewController : UIViewController <AVAudioPlayerDelegate, /*ADBannerViewDelegate,*/ UIActionSheetDelegate, GKLeaderboardViewControllerDelegate,
GKAchievementViewControllerDelegate, GameCenterManagerDelegate> {
// Game Center
GameCenterManager *gameCenterManager;
int64_t currentScore;
NSString* currentLeaderBoard;
IBOutlet UILabel *currentScoreLabel;
// End Game Center
IBOutlet UIImageView *ballpng;
IBOutlet UILabel *displaycredit2;
IBOutlet UILabel *displaycredits;
IBOutlet UIButton *easy;
IBOutlet UIButton *medium;
IBOutlet UIButton *hard;
IBOutlet UILabel *displayhighscore;
IBOutlet UILabel *Howtoplay;
IBOutlet UIButton *back;
IBOutlet UIButton *info;
IBOutlet UIButton *playbutton_mainmenu;
IBOutlet UIImageView *winder1;
IBOutlet UIImageView *socket1;
IBOutlet UIImageView *wheelcontrol2;
IBOutlet UILabel *seconds;
IBOutlet UILabel *scoreLabel;
IBOutlet UIButton *Restart;
IBOutlet UIButton *HIGHSCORE;
IBOutlet UIButton *pausebutton;
IBOutlet UIButton *resumebutton;
IBOutlet UIButton *gameStartButton;
IBOutlet UIImageView *mainmenu;
IBOutlet UIButton *credits;
IBOutlet UIButton *returnt
sample code for .m
#import <UIKit/UIKit.h>
#import "SideWinderViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Ball.h"
#import <AVFoundation/AVAudioPlayer.h>
// Game Center -- ignore and or delete
#import "AppSpecificValues.h"
#import "GameCenterManager.h"
// End Game Center
#implementation SideWinderViewController
-(void)viewDidLoad {
[Restart setHidden:NO];
...

Thats enough to show a button
Check
Xib shown is the right one
Is tht button is covered by some other view added via code
Is the button property hidden checked or unchecked
Check button Frame

Related

Xcode 4 storyboard, textfields not wanting to connect to IBOutlet

So in the storyboard i have a UIViewController class called FormViewController. I set the ViewController in the storyboard to use that:
I then have the three text fields in the header file:
#import <UIKit/UIKit.h>
#interface FormViewController : UIViewController
#property (strong, retain) IBOutlet UITextView *firstName;
#property (strong, retain) IBOutlet UITextView *lastName;
#property (strong, retain) IBOutlet UITextView *email;
- (IBAction) save:(id)sender;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
#end
However, when i try to connect the ones in the storyboard to the view controller, it doesnt pop up.
Any ideas?
UITextField and UITextView are two very different classes—you have created UITextField instances but your outlets are typed as UITextView.
Just change your outlet types to UITextField and all should be well!
(UITextView, for the record, is a scrolling, often editable field, more like a word processor.)

unable to detect UITextField

Hey guys I am unable to find or connect my UITextField loginId with my custom viewcontroller.h file. when I try to get that class using NSString *data = loginId.text;it tells me that it is non existant.
.h file:
#import <UIKit/UIKit.h>
UITextField *loginId;
UITextField *password;
#interface loginController : UIViewController
- (IBAction) loginBegin:(id) sender;
#end
.m file:
NSString *intakePass = loginId.text;
I tried cleaning my project but that seems not to work. I notice that when I go to the storyboard to add in a custom class usually the classname I make in the .h file will drop down but nothing comes up. But it is set to loginId.
Suggestions, thoughts?
IBOutlet is the Key to Make them visible in XIB. So u must specify them as IBOutlet.
You must drag UITextField from library, not other components.Please verify it on XIB that you are connecting Text Field and make sure the class name of text field. it should be UITextField or UITextField Subclass.
#interface loginController : UIViewController{
IBOutlet UITextField *loginId;
  IBOutlet UITextField *password;
}
#property(weak,nonatomic) IBOutlet UITextField *loginId;
#property(weak,nonatomic) IBOutlet UITextField *password;
- (IBAction) loginBegin:(id) sender;
#end
Apple Documentation says
IBOutlet your UITextField as below in your .m file:
#interface ViewController ()
#property(weak,nonatomic) IBOutlet UITextField *loginId;
#property(weak,nonatomic) IBOutlet UITextField *password;
#end
now you can connect your textfile in xib

Connecting IBOutlet to UITextView makes UITextView invisible

I have checked thoroughly for a solution to this (notably here: Can't connect IBOutlet in Interface Builder) but cannot see the solution. I have a UITextView that I am using as a text area in a form. I have connected it to this class member in IB:
IBOutlet UITextView *notes;
here is my .h
#import <UIKit/UIKit.h>
#import <AddressBookUI/AddressBookUI.h>
#interface U2MIDetailController : UIViewController <UITextFieldDelegate, UITextViewDelegate> {
IBOutlet UIButton *confirmButton;
IBOutlet UITextView *notes;
}
#property (nonatomic, retain) IBOutlet UITextView* notes;
#property ABRecordRef personObject;
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#end
and my .m, the relevant bits:
#synthesize notes;
- (void)viewDidLoad
{
[super viewDidLoad];
//set up delegates for keyboard hiding
notes.delegate = self;
notes.text = #"Notes";
...
}
In the links I've found some have solved this issue by checking the File's Owner "Class" attribute on the Identity inspector. How do I do that? I have attached a pic of the hierarchy which looks correct to me, the identity inspector doesn't jump out at me either as having any suspicious properties.
Here is a shot of the storyboard:
and here is how it looks int he simulator:
check your scrollview frame either it is fit to frame or not. put blackground color you know where you did mistake

Ios error: Thread 1 under #auto release pool "EXC_BAD_ACCESS

The app crashes and shows this error when I hit the Back button. I have 2 view controllers. On the first vc the Start button works fine to switch to second view, but when I hit the Back button the app crashes and I get the error above on the line below #autorelease pool. I will also post the code for my start & back buttons. thx :)
#import
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
First vc.H file Start Button (this works switching to second view)
#interface ViewController : UIViewController
{
IBOutlet UIButton *StartQuiz;
IBOutlet UIButton *HowToPlay;
IBOutlet UIButton *Credits;
IBOutlet UIButton *Back;
IBOutlet UILabel *Label;
}
-(IBAction)StartQuiz:(id)sender;
-(IBAction)HowToPlay:(id)sender;
-(IBAction)Credits:(id)sender;
-(IBAction)Back:(id)sender;
Firstvc.M file
#implementation ViewController
-(IBAction)StartQuiz:(id)sender {
Questions *MenuToQuestions = [[Questions alloc]
initWithNibName:#"Questions"
bundle:nil];
[self.view addSubview:MenuToQuestions.view];
}
SecondVC.h file (Back button crashes app)
#interface Questions : UIViewController
{
IBOutlet UIButton *BasicOptics;
IBOutlet UIButton *EyeAnatomy;
IBOutlet UIButton *OphthalmicInstruments;
IBOutlet UIButton *Lenses;
IBOutlet UIButton *Transposition;
IBOutlet UIButton *Standards;
IBOutlet UIButton *Frames;
IBOutlet UIButton *Random;
IBOutlet UIButton *Back;
IBOutlet UILabel *Cat1;
IBOutlet UILabel *Cat2;
IBOutlet UIButton *Right1;
IBOutlet UIButton *Right2;
IBOutlet UIButton *Right3;
IBOutlet UIButton *Right4;
IBOutlet UIButton *Wrong1;
IBOutlet UIButton *Wrong2;
IBOutlet UIButton *Wrong3;
IBOutlet UIButton *Wrong4;
IBOutlet UILabel *Answer1;
IBOutlet UILabel *Answer2;
IBOutlet UILabel *Answer3;
IBOutlet UILabel *Answer4;
IBOutlet UILabel *Question;
IBOutlet UILabel *SelectCategory;
IBOutlet UILabel *Lives;
IBOutlet UILabel *Score;
IBOutlet UILabel *LivesWord;
IBOutlet UILabel *ScoreWord;
IBOutlet UILabel *GameOver;
IBOutlet UILabel *FinalScore;
}
-(IBAction)BasicOptics:(id)sender;
-(IBAction)EyeAnatomy:(id)sender;
-(IBAction)OphthalmicInstruments:(id)sender;
-(IBAction)Lenses:(id)sender;
-(IBAction)Transposition:(id)sender;
-(IBAction)Standards:(id)sender;
-(IBAction)Frames:(id)sender;
-(IBAction)Random:(id)sender;
-(IBAction)Right:(id)sender;
-(IBAction)Wrong:(id)sender;
-(IBAction)Back:(id)sender;
#end
Secondvc.m file
-(IBAction)Back:(id)sender {
ViewController *MenuToViewController = [[ViewController alloc]
initWithNibName:#"ViewController"
bundle:nil];
[self.view addSubview:MenuToViewController.view];
}
You are not holding a reference for your MenuToViewController instance anywhere. The view of the MenuToViewController gets added to the view hierarchy, so it gets retained, but as soon as the view tries to send a message to one of the outlets, your app crashes, because the controller has been released.
Once you create that controller, you could set it as instance variable (add Questions *MenuToQuestions to your #interface).

can not move buttons

I have a little problem that my buttons doesn't move when I am using a code that should move the button.
ViewControlle.h:
#property (strong, nonatomic) IBOutlet UIButton *button1;
#property (strong, nonatomic) IBOutlet UIButton *button2;
ViewController.m:
#implementation GameViewController
#synthesize button1,button2;
code which should move the buttons:
button1.center=CGPointMake(button1.center.x, button1.center.y-10);
button2.center=CGPointMake(button2.center.x, button2.center.y+10);
why does the code not work or am I doing something wrong?
Because autolayout did not happen before view did load it will reset your locations.
when - (void)viewDidLayoutSubviews gets called its done so place your code here.
If you are using AutoLayout for ViewController than It's not work.
Uncheck the AutoLayout for ViewController.

Resources