I have create a few static UILabel text in Interface Builder, but when running the application. the label is not shown in the application itself, i do not know why.
all other stuff like textfield, buttons except the label is not working can anybody advise me what had gone wrong ?
This is in IB
this is in App
#import "SettingsViewController.h"
@implementation SettingsViewController
@synthesize drinkLimitText;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
appDelegate = (DrinkTabsAndNavAppDelegate *)[[UIApplication sharedApplication] delegate];
[super viewDidLoad];
NSLog(@"subView:%d",[self.view.subviews count]);
}
- (void) viewWillAppear:(BOOL)animated {
if ([appDelegate.drinkLimit floatValue] >= 0)
drinkLimitText.text = [NSString stringWithFormat:@"%.0f", [appDelegate.drinkLimit floatValue]];
else
drinkLimitText.text = @"0";
[super viewWillAppear:animated];
}
- (IBAction)textFieldDoneEditing:(id)sender{
NSDecimalNumber *tempValue = [[NSDecimalNumber alloc] initWithString:drinkLimitText.text];
if (tempValue == [NSDecimalNumber notANumber] || [tempValue doubleValue] < 0) {
NSString *msg = [[NSString alloc] initWithFormat: @"Make sure to enter a positive number."];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Hang on..."
message:msg
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
} else {
[sender resignFirstResponder];
[self updateDrinkLimit];
}
[tempValue release];
}
- (void)didReceiveMemoryWarning {
// Releases 开发者_开发技巧the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)updateDrinkLimit {
NSDecimalNumber *newLimit = [[NSDecimalNumber alloc] initWithString:[drinkLimitText text]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([newLimit floatValue] >= 0) {
[defaults setFloat:[newLimit floatValue] forKey:kDrinkLimitKey];
appDelegate.drinkLimit = newLimit;
} else {
[defaults setFloat:0 forKey:kDrinkLimitKey];
appDelegate.drinkLimit = 0;
}
[newLimit release];
}
- (IBAction)openOntrackWebsite {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.ontrack.org.au/"]];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[drinkLimitText release];
[super dealloc];
}
@end
Clean
your project and build
again.
This is one of the most common problem with Xcode.
My problem was not setting constraints properly. Make sure to set the width and height constraints and add any missing constraints by clicking on that triangle constraint button.
After fixing constraints, they show up.
Make sure you have saved your project. Also check whether you have done addSubView ion your code. Clean and then run... This will solve your issue
hope it helps....
Your hierarchy in interface builder should be as shown below:
UIView
--- Label
--- TextField
--- Label
--- UIButton
I suspect it is :
UIView
--- Label
--- UIButton
Label
Label
Is this xib example from your MainWindow or your ViewController for the tab bar item? Also, did you remember to change the NIB Name in the View Controller properties to the name, usually called SettingsViewController (the name of the xib file), which is what is usually generated if you used Xcode to create the class? In your screen shot, it says "View from 'Settings'", which may not be correct.
精彩评论