Question

first of all, I am beginner with xcode and programming in Objective-c. I made my app with navigation bar and I have UIView with class Lesson1 and I added new subview Level1 but I dont wanna add new class. Is it any solution how add label to subview Level1 from class Lesson1.m?

Thank you

Was it helpful?

Solution

It is very easy to do so. Let's admit this is your Lesson1 view code. In the viewDidLoad method you can add whatever you want.

- (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]
}

OTHER TIPS

Yes, you can.

Programmatically:

// viewDidLoad method from Lesson1 class
- (void)viewDidLoad
{
    self.level1 = // Your UIView

    [self.view addSubview:self.level1]
    [self.level1 addSubview:yourLabel]
}

Using XIB file for Lesson1:

Drag and drop an UILabel into your Lesson1 and link the UILabel with an IBoutlet on your Lesson1 class.

Use below link. It might be helpful for you!! http://www.techotopia.com/index.php/An_iOS_7_Core_Data_Tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top