ios UITableView 委托方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13156927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITableView delegate methods
提问by D_D
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
需要在编译时从另一个函数调用的委托方法……有没有UITableView
我可以使用的默认委托方法?如果没有,请评论如何在现有委托方法之外添加额外的委托方法。
Thanks in advance
提前致谢
回答by Nitin Gohel
Make sure you set UITableview
Delegate in either way - from NIB
or programatially
确保您UITableview
以任何一种方式设置委托 - 从NIB
或以编程方式
Using NIBFrom Nib :-
从笔尖使用笔尖:-
Programatically :-
以编程方式:-
then:-
然后:-
-(void)viewWillAppear:(BOOL)animated
{
tblService.delegate=self;
tblService.dataSource=self;
[super viewWillAppear:YES];
}
Use following delegates:
使用以下代表:
- (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
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
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];
}
回答by NSStudent
I don't know if this method exist but if you need other methods in a UITableView
delegate you can Create a new Category of UITableViewDelegate
.
我不知道此方法是否存在,但如果您需要UITableView
委托中的其他方法,您可以创建一个新的UITableViewDelegate
.