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 8551133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:07:38+00:00 2026-06-11T14:07:38+00:00

Basically, my problem is that I’m trying to create 3 instances of a UIView

  • 0

Basically, my problem is that I’m trying to create 3 instances of a UIView through a loop. I’m using ARC and I don’t really know if what I want to do is possible with it. Here’s the code I currently have :

NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"RoomView"
                                                  owner:self
                                                options:nil];
NSMutableArray *roomViews = [[NSMutableArray alloc] initWithCapacity:[gtb.rooms count]];

for (i = 0; i < [gtb.rooms count]; i++)
{
    RoomView *rcv = [[RoomView alloc] init];
    NSDictionary *room = [gtb.rooms objectAtIndex:i];
    rcv = [nibViews objectAtIndex:0];
    NSLog(@"Start rcv = %@", rcv);
    rcv.roomNumber.text = [NSString stringWithFormat:@"Chambre %d", i + 1];
    rcv.roomType.text = [room objectForKey:@"roomType"];
    [rcv setFrame:CGRectMake(0, sizeOfContent, rcv.frame.size.width, rcv.frame.size.height)];
    sizeOfContent += rcv.frame.size.height;
    [roomViews addObject:rcv];
    NSLog(@"End rcv = %@", rcv);
}

for (i = 0; i < [gtb.rooms count]; i++)
    NSLog(@"Room #%i : %@", i, [roomViews objectAtIndex:i]);

And here’s what I have in the logs :

2012-09-20 10:15:00.287 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 0; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.289 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 420; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.312 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 420; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.314 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 527; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.316 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 527; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.317 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.319 AppName[2792:707] Room #0 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.323 AppName[2792:707] Room #1 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.325 AppName[2792:707] Room #2 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>

I know if I wasn’t using ARC, I should have placed something like [rcv autoRelease] at the end of the loop, but with ARC, I can’t.

Is there any solution to solve it, or must I disable ARC for this file ?

Thanks for your help !

  • 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-11T14:07:39+00:00Added an answer on June 11, 2026 at 2:07 pm

    You need to replace this line:

    rcv = [nibViews objectAtIndex:0];
    

    With this one:

    rcv = [[nibViews objectAtIndex:0] copy];
    

    Because if not, you just are accessing the same view object, not a new one copied from it (strong reference not copied).

    And as a side not, there is no influence of ARC in that matter. You would have same problem without ARC. With ARC you are just not writing release/autorelease etc.

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

Sidebar

Related Questions

I have a homework problem that I really don't know how to start. Here
Basically this started with my problem that I had when trying to find if
The problem that I'm trying to resolve can be seen here: http://jsfiddle.net/AAyLj/14/ Basically, when
I am trying to solve a problem that involves basically implementing a logical AND
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
So basically, I've run into this problem enough times that it is seriously frustrating
I have a pretty simple problem. Basically I have an array called $list that
I've a problem with LINQ. Basically a third party database that I need to
Basically I want to achieve a tuple (or any datatype that fits my problem)
I am having a very weird problem that I've never had before when using

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.