iphone - Assigning a button tag from an array which stores integers -


i trying assign tag button. normal command is:

button.tag = 1; 

the tag must integer.

my problem assign integer stored in array (tabreference) yet again part of class (currentnotebook). need this:

int k = 0;     button.tag = [currentnotebook.tabreference objectatindex:k]; // warning. 

this doesn't seem work, however, xcode tells me: passing argument 1 of settag: makes integer pointer without cast.

my array looks (i tried use integers...):

nsmutablearray *trarray = [[nsmutablearray alloc] init];         nsnumber *anumber = [nsnumber numberwithinteger:1];         [trarray addobject: anumber];         [trarray addobject: anumber];         [trarray addobject: anumber];         [trarray addobject: anumber]; currentnotebook.tabreference = trarray; 

an nsmutablearray stores modifiable array of objects. can't directly store integer in nsmutablearray. that's why have store bunch of integers:

nsmutablearray *the_array = [[nsmutablearray alloc] init];  int max = 100;  (int = 0; < max; i++)  {     nsnumber *temp_number = [nsnumber numberwithint:arc4random() % max];      [the_array addobject:temp_number]; } 

of course, pretty same thing , store else in there:

nsmutablearray *the_array = [[nsmutablearray alloc] init];  int max = 100;  int max_x = 50; int max_y = 25; int max_w = 100; int max_h = 200;  (int = 0; < max; i++)  {     cgfloat temp_x = arc4random() % max_x;     cgfloat temp_y = arc4random() % max_y;     cgfloat temp_w = arc4random() % max_w;     cgfloat temp_h = arc4random() % max_h;      cgrect temp_rect = cgrectmake(temp_x, temp_y, temp_w, temp_h);      [the_array addobject:[nsvalue valuewithcgrect:temp_rect]];  } 

when go retrieve these values need specify want out of array because same array can contain different objects.

for integers:

for (int = 0; < max; i++)  {     nslog(@"%i: %i", i, [[the_array objectatindex:i] intvalue]); } 

for cgrect example:

for (int = 0; < max; i++)  {     cgrect temp_rect = [[the_array objectatindex:i] cgrectvalue];      nslog(@"%i: x:%f y:%f w:%f h:%f", i, temp_rect.origin.x, temp_rect.origin.y, temp_rect.size.width, temp_rect.size.height);  } 

in nutshell, storing objects not integers in code. have pull them out of there objects , extract integer data back.


Comments