Reputation: 17
I have to navigate from one screen to another on the click of the tableview cell plus i want the data on my cell to be transferred on the respective labels on my second view.i have connected the two view using a segue. how do i go about further ?thanks
Upvotes: 0
Views: 1063
Reputation: 458
You have VC1, which has a UITableView
, and VC2. When a VC1 UITableViewCell
is tapped, VC2 is shown with info from the cell. Schematically, in VC1 you implement:
#pragma mark - Table view delegate for VC1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
dataForVC2 = [vc1DataSource objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:segueFromVC1ToVC2 sender:self];
}
#pragma mark - View lifecycle
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:segueFromVC1ToVC2]) {
vc2 = (VC2ViewController *)[segue destinationViewController];
vc2.delegate = (id)self;
vc2.whatIWantFromVC1 = dataForVC2;
}
}
#pragma mark - VC2 delegate
- (void)VC2ControllerDidFinish:(VC2ViewController *)controller
{
dataBackFromVC2 = controller.propertyForVC1;
}
This is how you manage the segue. You also need to implement a delegate protocol for VC2, which is described very well in the WWDC 2011 Apple video, "Introduction to Storyboarding".
It is a lot of conceptual information to absorb but once you have understood the UITableView datasource
& delegate
, protocols, UINavigationController
, and segues then sophisticated UIs become straightforward to implement. A happy 2 days of hitting the Apple docs and the WWDC videos will lift the veil!
Upvotes: 1
Reputation: 8109
You really need to learn objective-C before jumping into the project development. here's a link to Apple's book: http://developer.apple.com/library/mac/documentation/cocoa/conceptual/objectivec/objc.pdf
Upvotes: 1