xcode 静态 UILabel 未显示在 uiview 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7102589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Static UILabel not showing in uiview
提问by Desmond
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.
我在 Interface Builder 中创建了一些静态 UILabel 文本,但是在运行应用程序时。该标签未显示在应用程序本身中,我不知道为什么。
all other stuff like textfield, buttons except the label is not working can anybody advise me what had gone wrong ?
所有其他东西,如文本字段、按钮,除了标签不起作用,有人能告诉我出了什么问题吗?
This is in IB
这是在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
回答by Devang
Clean
your project and build
again.
Clean
你的项目build
又一次。
This is one of the most common problem with Xcode.
这是 Xcode 最常见的问题之一。
回答by Aditya Mittal
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.
修复约束后,它们就会出现。
回答by P.J
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
确保您已保存您的项目。还要检查您是否已完成 addSubView 离子您的代码。清洁然后运行...这将解决您的问题
hope it helps....
希望能帮助到你....
回答by Praveen S
Your hierarchy in interface builder should be as shown below:
您在界面构建器中的层次结构应如下所示:
UIView
--- Label
--- TextField
--- Label
--- UIButton
I suspect it is :
我怀疑是:
UIView
--- Label
--- UIButton
Label
Label
回答by macboyrules
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.
这个 xib 示例是来自您的 MainWindow 还是 ViewController 中的选项卡栏项目?还有,你记得把 View Controller 属性中的 NIB Name 改成名字,通常叫 SettingsViewController(xib 文件的名字),如果你用 Xcode 创建类,通常会生成这个名字?在您的屏幕截图中,它显示“从‘设置’查看”,这可能不正确。