我在Interface Builder中创建了一些静态UILabel文本,但是在运行应用程序时。标签没有显示在应用程序本身,我不知道为什么。
所有其他内容,如textfield,除标签外的按钮都不起作用 任何人都可以告诉我出了什么问题?
这是在IB
这是在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
答案 0 :(得分:5)
Clean
您的项目和build
。
这是Xcode最常见的问题之一。
答案 1 :(得分:2)
我的问题是没有正确设置约束。确保设置宽度和高度约束,并通过单击该三角形约束按钮添加任何缺少的约束。
在修复约束后,它们会显示出来。
答案 2 :(得分:1)
确保已保存项目。 还要检查你的代码是否已经完成了addSubView。 清洁,然后运行...... 这将解决您的问题
希望它有所帮助......答案 3 :(得分:1)
界面构建器中的层次结构应如下所示:
UIView
--- Label
--- TextField
--- Label
--- UIButton
我怀疑是:
UIView
--- Label
--- UIButton
Label
Label
答案 4 :(得分:1)
来自MainWindow或ViewController的xib示例是否为标签栏项目?另外,您是否记得将View Controller属性中的NIB Name更改为名称,通常称为SettingsViewController(xib文件的名称),如果您使用Xcode创建类,通常会生成该名称?在您的屏幕截图中,它显示“从'设置'查看”,这可能不正确。