首先,我是初学者,在Objective-c中使用xcode和编程。我用导航栏制作了我的应用程序,我有UIView类Lesson1,我添加了新的子视图Level1,但我不想添加新类。是否有任何解决方案如何从Lesson1.m类的子视图Level1添加标签?
谢谢
答案 0 :(得分:1)
是的,你可以。
<强>编程:强>
// viewDidLoad method from Lesson1 class
- (void)viewDidLoad
{
self.level1 = // Your UIView
[self.view addSubview:self.level1]
[self.level1 addSubview:yourLabel]
}
使用第1课的XIB文件:
将UILabel拖放到Lesson1中,并将UILabel与Lesson1类上的IBoutlet链接。
答案 1 :(得分:1)
使用以下链接。它可能对你有所帮助!! http://www.techotopia.com/index.php/An_iOS_7_Core_Data_Tutorial
答案 2 :(得分:0)
这很容易实现。我们承认这是您的Lesson1视图代码。在viewDidLoad方法中,您可以添加任何内容。
- (void)viewDidLoad
{
UIView *level1 = [[UIView alloc] initWithFrame:CGRectMake(x,y,width,height)];
[self.view addSubview:level1]
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(label_x,label_y,label_width,label_height)];
label1.text = @"labeltext";
[level1 addSubview:label1]
}