UITableView委托方法 [英] UITableView delegate methods
本文介绍了UITableView委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个 UITableView
委托方法,需要在编译时从另一个函数调用...是否有任何默认 UITableView
委托我可以使用的方法?如果没有,请评论除了现有的方法之外如何添加额外的委托方法。
I need a UITableView
delegate method that need to be called from another function at compilation time...is there any default UITableView
delegate methods that i can use? if not, please comment on how to add an extra delegate method in addition to the existing ones.
提前致谢
推荐答案
确保设置 UITableview
以任何一种方式委派 - 从 NIB
或以编程方式
Make sure you set UITableview
Delegate in either way - from NIB
or programatially
使用NIB
来自笔尖: -
Using NIB From Nib :-
以编程方式: -
Programatically :-
然后: -
-(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;
}
以下用于设置单元格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
以下用于gatting特定单元格数据通过选择行此方法称为
- (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委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文