использовать 2 таблицы - PullRequest
       2

использовать 2 таблицы

0 голосов
/ 19 августа 2011

Привет всем, друзья, пожалуйста, как я могу использовать 2 TableView, я использую этот код, но моя проблема в том, что у меня такое же имя для 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;
        }
   }

1 Ответ

1 голос
/ 19 августа 2011

Хорошо, это будет простое объяснение, надеюсь, вы понимаете.Если вы не спросите, и я уточню.

Пример замедления TableView:

UITableView tableView1;
UITableView tableView2;

Каждое табличное представление имеет имя переменной, с которой оно ссылается, и отличается.Поскольку мы работаем с указателями, это позволяет нам делать следующее в методах делегата (Все они, это только один пример)

Пример метода делегата:

- (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;
}

И вы можетеиспользовать один и тот же подход для всех методов делагата

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...