Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:42:59+00:00 2026-05-22T17:42:59+00:00

Sorry, a beginner’s questions: I have created an instance of an UILabel and would

  • 0

Sorry, a beginner’s questions:

I have created an instance of an UILabel and would like to add copies of this UILabel to 4 different views. I tried the following code, but it won’t work as I am assigning the UILabel to one view and then assign it to the next — which results in the UILabel being removed from the first view. This carries on, so I end up with the UILabel being assigned only to the very last view:

    UILabel *titleTitle = [[[UILabel alloc] initWithFrame:CGRectMake(120, -48, 100, 28)] autorelease];
titleTitle.text = @"Index";
titleTitle.textColor = [UIColor blackColor];
titleTitle.backgroundColor = [UIColor clearColor];
titleTitle.font = [UIFont fontWithName:@"Ballpark" size:25.0f];
[indexView addSubview:titleTitle];
[indexView2 addSubview:titleTitle];
[indexView3 addSubview:titleTitle];
[indexView4 addSubview:titleTitle];

How can I manage to assign copies of UILabel to my views?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:43:00+00:00Added an answer on May 22, 2026 at 5:43 pm

    This is probably overkill for your needs, but if you must copy a complex object, then archiving and unarchiving it should work:

    NSMutableData *myData = [NSMutableData data];
    NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:myData] autorelease];
    
    [archiver encodeObject:titleTitle forKey:@"myTitle"];
    [archiver finishEncoding];
    NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:myData] autorelease];
    
    
    UILabel *t2 = [unarchiver decodeObjectForLey:@"myTitle"];
    // set location attributes
    [view addSubView:t2];
    [t2 release];
    
    UILabel *t3 = [unarchiver decodeObjectForLey:@"myTitle"];
    // set location attributes
    [view addSubView:t3];
    [t3 release];
    
    [unarchiver finishDecoding]; // Should be called once you will not decode any other objects
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First sorry I'm a big beginner. Would like to ask a more experienced developers
am sorry for this dumb beginner question, but i have a real problem understanding
sorry if this question is basic but I'm a beginner :(. I've created an
Sorry for this extreme beginner question. I have a string variable originaltext containing some
I'm a beginner with this so sorry for the silly question, I have a
Hi friends i'm beginner and sorry for simple Questions. how can i add new
Sorry, I'm a beginner with VB6. I have this: Private Sub Command5_Click() If MessageBox.Show(Sei
Sorry in advance for this being such a beginner question. Here are the steps
sorry for silly question, I am a beginner in obj-c. I wanted to add
this is a beginner type question, and I am sorry for my poor English.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.