0

I want to change the number of tableviews depending on my input, which will change depending on the user and i need to be able to reference these tableviews in my data source, as they should retain different data depending on the tableview. I figured this might be done if I could create a unique variable for each of the created tableviews, but i would need to be able to reference these variables through my whole class?

2
  • 4
    And what's the question? Commented Jun 22, 2012 at 2:25
  • 1
    my questions was if it was possible to create variables which i could reference through my whole class programmatically. Commented Jun 22, 2012 at 2:39

2 Answers 2

2

You can create an NSMutable Array and add UITableView in them directly . You can make create global variable store using static reference and access it globally .

@interface Singleton : NSObject {
  NSMutableArray *TableArray;
}
+ (Singleton *)instance;
@end

@implementation Singleton

+ (Singleton *)instance  {
    static Singleton *instance;

    @synchronized(self) {
        if(!instance) {
            instance = [[Singleton alloc] init];
        }
    }
    return instance;
}

The other alternative would be to include NSMutableArray in you appdelegate and access it throughout your application globally.

Creating objects dynamically is not a problem . you can create as many UITableview's and add them to an NSMutableArray using.

UITableview *temp = [UITableview alloc] initWithFrame : ... ];
temp.delegate = self ; 
tableArray.addObject(temp);

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath{

      if(tableView  = [tableArray objectAtIndex:x]{
        // do this 
       }
        else if (select appropriate table view from array ){

       }
       //do this for the rest
 }

What you are facing is an design issue . For other alternatives please refer Apple Guides for Objects Communication

Sign up to request clarification or add additional context in comments.

Comments

1

Why not create an NSMutableArray member variable to store them all? When you need to change the data source, set the specific tableview to the data source. I'm not sure of the details of what exactly you're trying to do, but adding them dynamically and changing the data source shouldn't be a problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.