cs1.6
cs1.6

Reputation: 159

use 2 tableview

Hi all freind, please how can I use 2 TableView ,i use this code but my problem is I have the same name for cellule

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       if (choix==1) {
            NSLog(@"%d",choix);
           return [mutable3 count]; 

       }
        else {
                NSLog(@"%d",choix);
            return [mutable2 count];    
        }
    }


    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (choix==1) {
            NSLog(@"cc%d",choix);
            static NSString *CellIdentifier = @"Cell";

            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            }
            cell.textLabel.text = [mutable3 objectAtIndex:indexPath.row];

            // Configure the cell...

            return cell;

        }
        else {
            NSLog(@"vvv%d",choix);

            static NSString *CellIdentifier = @"Cell";

            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            }
            cell.textLabel.text = [mutable2 objectAtIndex:indexPath.row];

            // Configure the cell...

            return cell;
        }
    }   
    #pragma mark -
    #pragma mark Table view delegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        if (choix==1) {

                NSLog(@"%d",choix);


        langue.text  =[mutable3 objectAtIndex:indexPath.row];   

            langView.hidden=TRUE;
        }
        else {

                NSLog(@"%d",choix);
            compain.text =[mutable2 objectAtIndex:indexPath.row];   

            langView.hidden=TRUE;
        }
   }

Upvotes: 0

Views: 262

Answers (1)

Armand
Armand

Reputation: 10254

Ok its going to be a simple explanation, hope you understand. If you dont please ask and I will elaborate.

TableView Decleration Example:

UITableView tableView1;
UITableView tableView2;

Each tableview has a variable name which it links to that differs. Because we are working with pointers it allows us to do the following in the delegate methods(All of them, this is only one example)

Delegate Method Example:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView== tableView1)
    {
         return 2;
    }
    else if(tableView== tableView2)  //this if statement is not really needed since if you only have 2 table views the second will automatically fall into the else
    {                           
        return 3;
    }
    else  //This else is only needed if you use the second if statement
        return 0;
}

And you can use the same approach for all delagate methods

Upvotes: 1

Related Questions