Saturday, June 8, 2013

UITableViewDelegate tableView didSelectRowAtIndexPath example in Objective C (iOS).


UITableViewDelegate tableView didSelectRowAtIndexPath

Tells the delegate that the specified row is now selected.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Parameters of [UITableViewDelegate tableView didSelectRowAtIndexPath]
tableView
A table-view object informing the delegate about the new row selection.
indexPath
An index path locating the new selected row in tableView.

Discussion of [UITableViewDelegate tableView didSelectRowAtIndexPath]
The delegate handles selections in this method. One of the things it can do is exclusively assign the check-mark image (UITableViewCellAccessoryCheckmark) to one row in a section (radio-list style). This method isn’t called when the editing property of the table is set to YES (that is, the table view is in editing mode). See "€œ“Managing Selections”" in Table View Programming Guide for iOS for further information (and code examples) related to this method.

UITableViewDelegate tableView didSelectRowAtIndexPath example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ContentController *detailview = [[ContentController alloc] initWithNibName:@"ContentController" bundle:nil];   
    detailview.detailString = [NSString stringWithFormat:@"%d",indexPath.row];
    [self.navigationController pushViewController:detailview animated:YES];    
    [detailview release];
}

Example of [UITableViewDelegate tableView didSelectRowAtIndexPath].
- (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];

}

UITableViewDelegate tableView didSelectRowAtIndexPath example.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    textfield.text = [yourarry ObjectAtIndex:inexPath.row];
}

End of UITableViewDelegate tableView didSelectRowAtIndexPath example article.