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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:01:21  来源:igfitidea点击:

UITableView delegate methods

iphoneiosipadios4

提问by D_D

I need a UITableViewdelegate method that need to be called from another function at compilation time...is there any default UITableViewdelegate 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 UITableviewDelegate in either way - from NIBor programatially

确保您UITableview以任何一种方式设置委托 - 从NIB或以编程方式

Using NIBFrom Nib :-

从笔尖使用笔尖:-

enter image description here

在此处输入图片说明

Programatically :- enter image description here

以编程方式:- 在此处输入图片说明

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 UITableViewdelegate you can Create a new Category of UITableViewDelegate.

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