UITableView的委托方法

我需要一个UITableView委托方法,需要在编译时从另一个函数调用…是否有任何默认的UITableView委托方法,我可以使用? 如果没有,请评论如何添加一个额外的委托方法,除了现有的。

提前致谢

确保你以任何方式设置UITableview委托 – 从NIB或程序

从Nib 使用NIB : –

在这里输入图像说明

以编程方式: – 在这里输入图像说明

然后:-

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

我不知道这个方法是否存在,但是如果你需要UITableView委托中的其他方法,你可以创build一个新的UITableViewDelegate