2012-10-31 12 views
18

ho bisogno di un metodo UITableView delegato che ha bisogno di essere chiamato da un'altra funzione al momento della compilazione ... c'è qualche difetto UITableView metodi delegato che posso usare? in caso contrario, si prega di commentare come aggiungere un metodo delegato aggiuntivo in aggiunta a quelli esistenti.UITableView metodi delegato

Grazie in anticipo

+0

do u necessità di aggiornare la tableView da un'altra funzione ??? – AppleDelegate

+0

perché vuoi creare il metodo delegato? Invece, è possibile ricaricare tutti i dati della tabella dopo il completamento della funzione –

+0

si prega di fornire ulteriori informazioni sul problema e ciò che si vuole raggiungere. – Kassem

risposta

39

Assicurarsi di impostare UITableview Delegato in entrambi i casi - da NIB o programatially

Utilizzando NIB Da Pennino: -

enter image description here

Programatically: - enter image description here

poi : -

-(void)viewWillAppear:(BOOL)animated 
{ 
     tblService.delegate=self; 
     tblService.dataSource=self; 
     [super viewWillAppear:YES]; 
} 

utilizzare i seguenti delegati:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; //count of section 
} 


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

    return [catagorry count]; //count number of row from counting array hear cataGorry is An Array 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView 
      cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *MyIdentifier = @"MyIdentifier"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:MyIdentifier] autorelease]; 
     } 

     // Here we use the provided setImageWithURL: method to load the web image 
     // Ensure you use a placeholder image otherwise cells will be initialized with no image 
     [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] 
         placeholderImage:[UIImage imageNamed:@"placeholder"]]; 
      cell.textLabel.text = @"My Text"; 
     return cell; 
    } 

Below use for set height of cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

     return 80; 

} 

Below use for gatting particular cells data by selecting row this method called

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

     Yourstring=[catagorry objectAtIndex:indexPath.row];  

     //Pushing next view 
     cntrSecondViewController *cntrinnerService = [[cntrSecondViewController alloc] initWithNibName:@"cntrSecondViewController" bundle:nil]; 
     [self.navigationController pushViewController:cntrinnerService animated:YES]; 

} 
+0

http://stackoverflow.com/questions/5831813/delegate-and-datasource-methods-for-uitableview/42105964#42105964 –

4

non so se questo metodo esiste, ma se avete bisogno di altri metodi in un UITableView delegato è possibile creare una nuova categoria di UITableViewDelegate.

Problemi correlati