ACCESSING SUB-VIEW SELECTION OF UITABLEVIEW IN IOS.

Maria Susan

Total Post:29

Points:107
Posted by  Maria Susan
 543  View(s)
Ratings:
Rate this:
I have created a view controller in iPhone app, which has a button. On button click we open a UITableViewController, on this table view we populate data using a mutable array 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 of MyTableViewController.m
#import "MyTableViewController.h"
@implementation MyTableViewController

@synthesize arrayList, tableView, selectedItem;
Now, I have no problem to open that table view on button click, but I can not figure-out what are the properties of the selected item.
  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Accessing sub-view selection of UITableView in iOS.

    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 like this:
    -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:
    (NSIndexPath *)indexPath
    {
        NSLog(@"Row selection Changed");
    }

      Modified On Jan-07-2016 07:17:41 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!