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

  • SEARCH
  • Home
  • 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 7897299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:07:53+00:00 2026-06-03T08:07:53+00:00

I have some confusion. Not really a bug or issue I am facing. I

  • 0

I have some confusion. Not really a bug or issue I am facing. I want to know something and I am not sure this is right place for this kind of question but here is my question:

In reference to my Question Here I was trying to map single gesture on two views.

Now I am keen to know that why this is not working? I went on basics that in case I have any NSObject subclass lets say if NSString and I add this in an NSMutableArray as follows:

 NSString *strTest = @"Test String";
 [aryTest1 addObject:strTest];
 [aryTest2 addObject:strTest];

String gets added in both of array. Now what I am doing is I created a label, set tag for the label and added that in two views as follows:

 UILabel *lblTemp = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
[lblTemp setTag:1];
[lblTemp setText:@"Label"];
[vw1 addSubview:lblTemp];
[vw2 addSubview:lblTemp];

Now every view has an array of subview. When we try to add an object in that view’s subview why this is not being added in both of view?
I am getting a result that my second view is showing the label but first view is not having the label.

If I comment the last line of my code and don’t add label in vw2 the label will be added in vw1. Than I tried a different thing.

UILabel *lblTemp = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
[lblTemp setTag:1];
NSMutableArray ary1 = [[NSMutableArray alloc] init];
NSMutableArray ary2 = [[NSMutableArray alloc] init];
[ary1 addObject:lblTemp];
[ary2 addObject:lblTemp];

both array has count 1. Thats mean that I have label added in my array. after that I tried to add array’s object in view than even ame problem. Label is only being added in second view:

 [vw1 addSubview:[ary1 objectAtIndex:0]];
 [vw2 addSubview:[ary2 objectAtIndex:0]];

When I printed retainCount of Label after initialize, adding in array1 and array2 everytime the retaincount was 1. So I think the array are not keeping the reference of same object. Its a new object copied in array. Than why label is not being added in same view?

What is actual internal process for a object to add on any view’s subview. As of I know subview is an Array type than what happening? Can anyone explain me?

Thanks in Advance

  • 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-06-03T08:07:54+00:00Added an answer on June 3, 2026 at 8:07 am

    The difference is that addSubview automatically removes a view from it’s super view before adding it to the new view (See the class reference: http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/uiview_class/uiview/uiview.html) while an array will happily accept an object even if it is in another array.

    You can create a copy of the label and place it in the other view though if this is what you need to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this sounds confusing: I have just built some basic prev/next pagination for
I have some perl code that looks something like this: my @array = map
I still have some confusion about this thing. What I have found till now
I have some confusion about when to use the self keyword during ivars assignment,
I am learning JPA from this tutorial . I have some confusions in understanding
I have searched and found some info on this topic but the answers are
I have some confusion about how to use AtlasLabel. It seems Label consume a
I am not sure if what I want to do breaks Object oriented guidelines
So I have seen some other posts similar, but not quite answering what I
I am developing a Java Desktop Application but have some confusions in choosing a

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.