NSMutableArray objectatindex always shows the last Object

my problem is that my NSMutableArray always get the last element with the objectatindex-method.

I have an array with some classes derived from UIViewController. I want to show one View after another.

first i fill the array:

ContactViewController *ContactView = [[ContactViewController alloc]init];
QuestionViewController *QuesView = [[QuestionViewController alloc]init];;
ContactView.mydelegate = self;
[QuesView setDelegate:self];


[Views addObject:ContactView];

Views =[[NSMutableArray alloc]initWithCapacity:11];
for (int i = 0; i < 11; i++) {
    [QuesView setParam:@"text" :i ];
    [Views addObject:QuesView];
}

after that i want to get the actual view and jump to the next like that:

-(IBAction)Button:(id)sender
{

    UIViewController *newView = [[UIViewController alloc]init];
    newView =  (UIViewController*)[Views objectAtIndex:enumerator];
    [self presentViewController:newView animated:YES completion: nil];
    enumerator++;
     //dismiss old view here....

    NSLog(@"number %d",[newView getNumber]);
}

the new view is not shown and the number in the log is always the last number of the array. I tried to go with a for loop through all element in "Views" but there is always the last number in every object....

any hints?

Answers


You probably want to create multiple QuestionViewController instances. But you actually create only one object and call setParam on it 11 times.

Also this line [Views addObject:ContactView] has no effect, because you create a new array object and assign it to Views in the next line. The same thing with UIViewController *newView = [[UIViewController alloc]init]. Hope you are using ARC, otherwise this would create a memory leak!


Need Your Help

how do I float a div over a background image in a different div

css html nested

In my CSS, I've created a menubar &lt;div&gt; and a header &lt;div&gt;. My intention is to have the menu line flush with the BOTTOM of the header's background image, so I've nested the menu inside ...

Why isn't my curved text centering itself?

ios objective-c math geometry core-animation

I have a UIView subclass called dpCurvedLabel. It uses CATextLayers to curved text around an arc. It works fine, except that I can't get it perfectly centered in the layers parent view. I want the ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.