Jeromiin
Jeromiin

Reputation: 71

Conflict between two different tableview xCode

I've got serious problem with two of my tableview being side by side. I made an interface where I can see folders (named as Collection) and if a tap on a button it shows me informations about data (named as Likes).

But, I don't really understand why many methods works and cellForRowAtIndexPath don't. Here is where the problem is :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   if (tableView == _collectionTableView)

So, this if just doesn't work. He got me to sigabrt everytime. Because My all functions have 3 choices : If you are _collectionTableView, there you go. Else if you are "_LikesTableView", there you go, ELSE there it's nil.

BUT, If I take the _LikesTableView to be the first choice, all works except it will send me that I am _LikesTableView, even if the others methods like :

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

Get me as _CollectionTableView ... So my logs are pretty funny It goes from "I am _CollecTableView" to "I am _LikesTableView" only for the cellForRowAtIndexPath.

It's pretty annoying that I can't get my _CollectionTableView to work properly, while my _LikesTableView seems to work very well if it goes in the "if" in place of the "else if".

So I suppose that I don't use the method very well, of that my If shouldn't mention the name of my tableview in this method... So, if anyone is able to help me, it would be really, really, really appreciated !

Thanks a lot. EDIT : The famous logs:

2014-08-14 11:40:07.269 [TestLog] Je le prend bien en compte le collectableview
2014-08-14 11:40:07.269 [TestLog] Je le prend bien en compte le collectableview
2014-08-14 11:40:07.270 [TestLog] Je le prend bien en compte le collectableview
2014-08-14 11:40:07.842 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:07.843 [TestLog] Je suis LikesTableView
2014-08-14 11:40:07.950 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:07.951 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.070 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.070 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.191 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.191 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.286 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.287 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.355 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.356 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.428 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.429 [TestLog] Je suis LikesTableView
2014-08-14 11:40:08.502 [TestLog] Je passe bien dans le cellforrow
2014-08-14 11:40:08.502 [TestLog] Je suis LikesTableView

Hope that could help >____<"

Upvotes: 0

Views: 96

Answers (2)

Raj
Raj

Reputation: 103

I agree with Casey's approach of using tags for comparison. Also you could have a separate data source for each table view, just to avoid confusion, if it is possible in your design. So another class which conforms to UITableViewDataSource should be created. This new class can be assigned as the dataSource for one of the tableView's.

Upvotes: 1

Casey
Casey

Reputation: 103

How about consider using tag for your tableView.

First set tag of your collectionTableView at where you initialised it, for example viewDidLoad

_collectionTableView.tag = 1;

and at your cellForRowAtIndexPath, instead of if (tableView == _collectionTableView) , use tag to check which tableView is calling the method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (tableView.tag == 1)
   {
    ///do something
   }
   else
   {
    ///do something
   }
}

Upvotes: 1

Related Questions