omrehman
omrehman

Reputation: 107

UITableView does not responding to selection of UITableViewCell

i have created a UItableView named _tableView, here is the code for table view in view.m

   - (void)viewDidLoad
   {
         [super viewDidLoad];

         tableData = [NSArray arrayWithObjects:@"Team Members",@"MembershipStatus",@"relation of status",@"Registerd events", nil];
                [_tableView setUserInteractionEnabled:TRUE];
                 [_tableView  reloadData];
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [tableData count];
    }

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 54;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [newCell setUserInteractionEnabled:TRUE];
        newCell.textLabel.text = [tableData objectAtIndex:indexPath.row];
        return  newCell;

    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"id");
    }

while executing the code I got the table correctly. But when i am selecting one of the list item it won't respond. (i.e., the NSLog is not working). did i miss something ?? or what i do wrong ??

Upvotes: 0

Views: 824

Answers (4)

Jyotiraditya
Jyotiraditya

Reputation: 11

check in .h file @interface MyView : UIViewController is set or Not. if its not set then Set 1st there. then in .m File while Creating TableView there you just write

_tableView.delegate = self; _tableView.dataSource = self;

Upvotes: 0

codercat
codercat

Reputation: 23271

Check with your code

@interface ClassName : UIViewController <UITableViewDelegate, UITableViewDataSource>
in viewDidLoad:


self.tableView.delegate = self;
self.tableView.dataSource = self;

or

_tableView.delegate = self;
_tableView.dataSource = self;

Upvotes: 0

Gaurav Singh
Gaurav Singh

Reputation: 1997

In your -viewDidLoad write:

[_tableView setDelegate:self];

Upvotes: 2

Suhit Patil
Suhit Patil

Reputation: 12023

check if the tableview's delegate is set to your viewController

@interface MyView : UIViewController <UITableViewDelegate, UITableViewDataSource>

in viewDidLoad:

self.tableview.delegate=self;

Upvotes: 0

Related Questions