jan salawa
jan salawa

Reputation: 1208

iPhone - multiple tables in one view

I'm looking for guidances on building interface for my test application. I'm new to iPhone development so I'm not sure how should I approach it.

I want to display elements in multiple tables in one view. It should be possible to change table using swipe gesture and drag it's elements between each of tables. I plan to add some cool animation for dragging and adding new elements to tables. Should I use 'drawing 2d graphic' for that purpose or is there other way to do it (reuse tableview). Does anyone have any examples how to do it?

Upvotes: 0

Views: 180

Answers (2)

Nazim
Nazim

Reputation: 64

It would be complicated but a way to go...

Keep one datasource & delegate.This means that all the delegate/datasource methods become more complicated BUT it means that you can retain the one to one relationship between viewController & view.

keep a reference to each of the table views

//vc.h

@property (nonatomic, weak) IBOutlet UITableView* firstTableView;
@property (nonatomic, weak) IBOutlet UITableView* secondTableView;

In the datasource/ delegate methods you need to account for the fact that the method needs to behave differently depending on which table view is in use. e.g.

//vc.m

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

    ...

    if (tableView == self.firstTableView) {

        ...

    } else { // tableView == self.secondTableView

        ...
    }
}

return cell;

}

Upvotes: 2

Schemetrical
Schemetrical

Reputation: 5536

Use two UITableViews in one UIViewController. Have each of their delegates and datasources in different model classes. To drag things between them, you will need to create a table view cell view when you start holding on a table view cell so that when it is duplicated, you can move it around using a UIGestureRecognizer. Once you have that, to drop it into another UITableView, you'll need to check for its position and drop it in. Remember to update your model.

This is not very easy to do as you'll need to do many positioning and math stuff, but I'm sure you'll be able to figure it out.

Upvotes: 1

Related Questions