views:

31

answers:

1

The Code:

    // Inside my BoardsViewController.m
- (void)createImage {

    imageCounter ++; 
    board = [[Boards alloc] init]; 
    [self.view addSubview:board];
    [board release];

board is supposed to be changed everytime, and is instead of being named board: be named 1_board, 2_board, 3_board, everytime I call this method

}

I want to have the Boards(UIView subclass) have the name of imageCounter, and also have board. Kinda like: 1_board. Meaning I want to have a Boards called something different everytime I call this method.

EDIT:
This should help maybe:

I want to have this one method that I will call multiple times allocate a Board(subclass of UIView) but have them all different names other than only one name. Meaning I increment the view counter everytime before allocating the view. So I want to have the name include the variable inside the integer: viewCounter. So that I cal call the different views seperatly and control each allocation differently.

+2  A: 

It is not clear what do you want to achieve. If you want to distinguish between different Board instances later you can use a tag property (available in all UIView subclasses):

- (void)createImage {
    imageCounter ++; 
    Boards *board = [[UIImageView alloc] init]; 
    board.tag = imageCounter;
    [self.view addSubview:board];
    [board release]; // Note that you need this line also, you current code produces memory leak
}

Later you can get each of the created Boards using:

Boards* yourBoard = [self.view viewWithTag: someTag];

You can also define some custom identifier in your Board class if you want. Changing the name of the local variable (e.g. board to whatever_board) does not really make sense as this name will not be accessible outside of the scope of this function anyway.

Vladimir
Actualy I am doing that so that you know that I am not just using a UIView
Jaba
Everything clear now? (because I'm still a bit confused :) )
Vladimir
Yep this works, Im not the greatest at asking questions. Thanks for dealing with my great incompetantcy.
Jaba
OK, I'm not the greatest answerer as well, that's why I'm concerned
Vladimir