Nivesh Singh Nivesh Singh - 1 year ago 43
iOS Question

using a framework for two different view controllers and array

I m using

. It's working fine on my
First view controller
. Now I want to use this in different View controller with different
array. How can I achieve this? This is how I do in my
first ViewController

CGRect frame = self.invitationViewContainer.frame;
//frame.origin.y = -self.view.frame.size.height; //optional: if you want the view to drop down
DraggableViewBackground *draggableBackground = [[DraggableViewBackground alloc]initWithFrame:frame];
draggableBackground.alpha = 0; //optional: if you want the view to fade in

[draggableBackground loadCards:_arrAllCards];

[self.invitationViewContainer addSubview:draggableBackground];

and in
DraggableViewBackground ViewClass


exampleCardLabels = array;

if([exampleCardLabels count] > 0) {
NSInteger numLoadedCardsCap =(([exampleCardLabels count] > MAX_BUFFER_SIZE)?MAX_BUFFER_SIZE:[exampleCardLabels count]);
//%%% if the buffer size is greater than the data size, there will be an array error, so this makes sure that doesn't happen

//%%% loops through the exampleCardsLabels array to create a card for each label. This should be customized by removing "exampleCardLabels" with your own array of data
for (int i = 0; i<[exampleCardLabels count]; i++) {
DraggableView* newCard = [self createDraggableViewWithDataAtIndex:i];
[allCards addObject:newCard];

if (i<numLoadedCardsCap) {
//%%% adds a small number of cards to be loaded
[loadedCards addObject:newCard];

for different JSON array can I use the same Classes or I have to make different classes?

Answer Source

You can use same DraggableViewBackground class for multiple viewcontrollers. You just need to change the array from this line,

[draggableBackground loadCards: yourArray];

If you want to change the design & data of card, you can use another DraggableViewBackground class. Copy all methods from DraggableViewBackground to your new DraggableViewBackground class.

In the new DraggableViewBackground.m change -(void)setupView method according your design. Change -(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index method according to your data.

And use new DraggableViewBackground class to your secondViewController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download