2012-10-31 183 views
18

我需要一個UITableView委託方法,需要在編譯時從另一個函數中調用...是否有任何默認UITableView我可以使用的委託方法?如果沒有,請評論如何添加一個額外的委託方法,除了現有的。UITableView委託方法

在此先感謝

+0

做ü需要從另一個函數刷新的tableView ??? – AppleDelegate

+0

你爲什麼要創建委託方法?相反,您可以在完成功能 –

+0

後重新加載所有表格數據,請提供有關該問題以及您想要實現的更多信息。 – Kassem

回答

39

確保在任一方式設置UITableview代表 - 從NIB或programatially

使用NIB 從筆尖: -

enter image description here

編程方式: - enter image description here

然後: -

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

使用下列代表:

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

我不知道,如果這種方法存在,但如果你需要在一個UITableView委託其他方法可以創建UITableViewDelegate一個新的類別。