Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView delegate methods [closed]

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.

Thanks in advance

like image 943
DD_ Avatar asked Oct 31 '12 11:10

DD_


People also ask

What is UITableView delegate?

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

What are delegate and DataSource methods of UITableView?

Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..

What is difference between delegate and DataSource in iOS?

A data source is almost identical to a delegate. The difference is in the relationship with the delegating object. Instead of being delegated control of the user interface, a data source is delegated control of data.

Which method is used to allow moving of row in UITableView?

moveRow(at:to:) Moves the row at a specified location to a destination location.


2 Answers

Make sure you set UITableview Delegate in either way - from NIB or programatially

Using NIB From 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

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

}
like image 149
Nitin Gohel Avatar answered Oct 25 '22 11:10

Nitin Gohel


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.

like image 21
NSStudent Avatar answered Oct 25 '22 11:10

NSStudent