views:

195

answers:

1

Hi all, I just want to get the value of a cell in the table view when i tap on it.. can any one help me in this.?

Thanks in Advance Shibin Moideen

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    appDelegate.courseName=[appDelegate.courses objectAtIndex:indexPath];
    NSLog(@"%@",appDelegate.courseName);
    DetailCourseViewController *detailController = [[DetailCourseViewController alloc]
                   initWithNibName:@"DetailCourseView" bundle:nil];
    [self presentModalViewController:detailController animated:YES];
}

is that done in this way. also i need to store that value in a string which i declared in the app delegate.

A: 

You use the tableView:didSelectRowAtIndexPath: delegate method and use the indexPath to return the cell that was tapped.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"%@", cell);
}
Garrett
Thanks,But i am getting this as output.2009-10-02 12:20:54.264 WTYou[5742:20b] <UITableViewCell: 0xd49940; frame = (0 44; 320 44); autoresize = W; layer = <CALayer: 0xd4b530>>
Shibin Moideen
What are you trying to do with the cell? You need to return the `indexPath.row` to the objectAtIndex, not the section and row.
Garrett
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { appDelegate.courseName=[tableView objectAtIndex:indexPath.row]; NSLog(@"%@",appDelegate.courseName);}This is what i need. i need to store the data in a string declared in appDelegateis that correct.?help me please...!
Shibin Moideen
You can't just set your `courseName` to the `UITableViewCell`, you need to access the row first then read it's `textLabel`. You also need to edit your question because I already answered what you asked for, this is something more.
Garrett
You also have a 0% accept rate, you should start accepting answers and more people will answer your questions.
Garrett