---
title: "Accessing sub-view selection of UITableView in iOS."  
description: "Accessing sub-view selection of UITableView in iOS."  
author: "Anonymous User"  
published: 2016-01-07  
updated: 2016-01-07  
canonical: https://www.mindstick.com/forum/33843/accessing-sub-view-selection-of-uitableview-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Accessing sub-view selection of UITableView in iOS.

I have created a [view controller](https://www.mindstick.com/forum/33709/how-to-use-table-view-controller-with-small-sized-in-ios) in [iPhone app](https://www.mindstick.com/articles/208914/4life-innovations-is-bracing-up-to-acquire-ios-13-for-iphone-app-development), which has a button. On [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click) we open a UITableViewController, on this [table view](https://www.mindstick.com/forum/33654/send-table-view-cell-value-on-button-action-in-ios) we [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) data using a [mutable array](https://www.mindstick.com/forum/33695/sorting-mutable-array-in-ascending-order-in-objective-c) and that array has several NSDictionary objects.\

```
#import <UIKit/UIKit.h>@interface MyTableViewController:UITableViewController{  NSMutableArray *arrayList;  NSIndexPath *last;  IBOutlet UITableView *tableView;  NSObject *selectedItem;}@property(nonatomic, retain) NSArray *arrayList;@property(nonatomic, retain) UITableView *tableView;@property(nonatomic, retain) NSObject *selectedItem;@end
```

this is the [Implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) of MyTableViewController.m\

```
#import "MyTableViewController.h"@implementation MyTableViewController@synthesize arrayList, tableView, selectedItem;
```

Now, I have no [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) to open that table view on button click, but I can not figure-out what are the [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) of the selected item.\

## Replies

### Reply by Tarun Kumar

For accessing selection in **UITableView** you can use **-indexPathForSelectedRow** method to determine which row is selected, this is a predefined method of table view.\
You can use this method like this:\

```
NSIndexPath *selectedIndex = [myTableView indexPathForSelectedRow];if(selectedIndex) {   NSLog(@"Section No:%u and Row No:%u", [selectedIndex row],                                         [selectedIndex section]);} else {   NSLog(@"Please select a Row!");}
```

The Log message will display in the console on selection changes.\
and implement **didSelectRowAtIndexPath:** method, it is a delegate method of table view in your view [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) like this:\

```
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:                                         (NSIndexPath *)indexPath{    NSLog(@"Row selection Changed");}
```

\


---

Original Source: https://www.mindstick.com/forum/33843/accessing-sub-view-selection-of-uitableview-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
