2012-08-06 11 views

risposta

17

Ecco perché i metodi dataSource/delegate hanno un parametro tableView. A seconda del suo valore, è possibile restituire diversi numeri/celle/...

- (void)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView == _myTableViewOutlet1) 
     return 10; 
    else 
     return 20; 
} 
+0

e poi come dato valori di testo delle cellule e didSelect metodo fila – user1567956

+2

Tutte origine dati/metodi delegato avere un parametro 'tableView'. Non solo 'numberOfRowsInSection', ma anche' cellForRowAtIndexPath' o 'didSelectRowAtIndexPath'. – Cyrille

2

Tutte le vostre UITableViewDelegate e UITableViewDatasource metodi saranno attuati solo una volta. Hai solo bisogno di verificare per quale vista tabella viene chiamato il metodo.

if (tableView == tblView1) { 
    //Implementation for first tableView 
} 
else { 
    //Implementation for second tableView 
} 

questo sarà il lavoro in tutte le delegato e origine dati i metodi di tableView come tableView è parametro comune a tutti i metodi

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {} 
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {} 

sguardo here e here

This Link ha anche la soluzione del vostro problema.

Spero che questo aiuti

2

Si prega di dare un'occhiata.

Prima creare due tableview nel generatore di interfacce e quindi connettersi con due variabili IBOutlet e impostare delegate e origine dati per entrambe le tabelle.

In interfaccia del file

-IBOutlet UITableView *tableView1; 
-IBOutlet UITableView *tableView2; 

Nel file di implementazione

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     if (tableView==tableView1) 
     { 
     return 1; 
     } 
     else 
     { 
     return 2; 
     } 
    } 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView==tableView1) 
    { 
     return 3; 
    } 
    else 
    { 
     if (section==0) 
      { 
      return 2; 
      } 
      else 
      { 
      return 3; 
      } 
    } 
    } 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) 
      { 
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
      } 

    if (tableView==tableView1) 
     { 
      //cell for first table 
     } 
    else 
     { 
      //cell for second table 
      } 
    return cell; 
} 

Usa questo codice. speranza aiuta

Problemi correlati