Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd multiple NSSlider to view programmatically
    text
    copied!<p>I'm new to objective C and Cocoa, but I have managed to add a slider into some views etc. I got that. </p> <p>I want to add multiple sliders with code, and I tried it with a for loop and a array. It didnt work, but here is the Code I tried:</p> <pre><code>NSMutableArray* myarray; for (int i = 0; i&lt;5; i = i+30) { [myarray addObject:[[NSSlider alloc] initWithFrame:NSMakeRect(15+i, 15, 30, 200)]]; } for (int i=0; i&lt;5; i++) { [firstView addSubview:[myarray objectAtIndex:i]]; NSLog(@"%d",i); } </code></pre> <p>(wanted to show them 30 apart, but doesnt matter it didnt work. Then I tried this if its even working "through" an array</p> <pre><code>[myarray addObject:[[NSSlider alloc] initWithFrame:NSMakeRect(15, 15, 30, 200)]]; [firstView addSubview:[myarray objectAtIndex:0]]; </code></pre> <p>I tried to show only one slider. Doesnt work either.</p> <p>But this works:</p> <pre><code> [firstView addSubview:[[NSSlider alloc] initWithFrame:NSMakeRect(45, 15, 30, 200)]]; </code></pre> <p>Why? And what is the right way to add multiple sliders/buttons/whatever doesnt really matter to add to a view dynamically? The real Idea is to get Data from CoreData and for each entry in CoreData it should Display a slider. (But thats far away)</p> <p>I need some tips and tricks! Thanks in advance guys!</p> <p>BTW when I try to init the array this way:</p> <pre><code>NSMutableArray* myarray = [[NSMutableArray alloc] init]; </code></pre> <p>the views dont load (firstView especially because this view is black)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload