Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass data to detail view after being selected in a uitableview cell
    text
    copied!<p>I have a <code>UITableViewController</code> that has data populated from an NSMutableArray called userList. When specific user is selected, it goes to a detail view but it wont display the data in a <code>UITextview</code> and <code>UIImageview</code> in the <code>UIView</code>.(Detailview).I am Using Story board.This is my Sample code.</p> <p>please give me any idea. Thanks in advance.</p> <p><strong>Tableviewcontroller.m</strong></p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // tableData=[NSArray arrayWithObjects:@"Alto",@"Estilo",@"Swift",@"Honda CRV",@"Ritz", nil]; thumbnails=[NSArray arrayWithObjects:@"car1.jpg",@"car2.jpg",@"car3.jpg",@"car4.jpg",@"car5.jpg", nil]; Car *car1=[Car new]; car1.carName=@"Alto"; car1.imageFile=@"Exotic_Car_-_Bugatti.jpg"; car1.carDetails=[NSArray arrayWithObjects:@"Harsha Mar05,2019",@"Registration AP2911234",@"Model Year 2009",@"CarModel Alto",@"Engine StreamEngine",@"Petrol Petrol",@"Exterior Color Black",@"interior Color Grey",@"Fuel Economy 1000",@"Insurance Insurance",@"Life time tax Free", nil]; Car *car2=[Car new]; car2.carName=@"Estilo"; car2.imageFile=@"images.jpg"; car2.carDetails=[NSArray arrayWithObjects:@"Harsha Mar05,2019",@"Registration AP2911234",@"Model Year 2009",@"CarModel Alto",@"Engine StreamEngine",@"Petrol Petrol",@"Exterior Color Black",@"interior Color Grey",@"Fuel Economy 1000",@"Insurance Insurance",@"Life time tax Free", nil]; Car *car3=[Car new]; car3.carName=@"Swift"; car3.imageFile=@"images1.jpg"; car3.carDetails=[NSArray arrayWithObjects:@"Harsha Mar05,2019",@"Registration AP2911234",@"Model Year 2009",@"CarModel Alto",@"Engine StreamEngine",@"Petrol Petrol",@"Exterior Color Black",@"interior Color Grey",@"Fuel Economy 1000",@"Insurance Insurance",@"Life time tax Free", nil]; Car *car4=[Car new]; car4.carName=@"Honda CRV"; car4.imageFile=@"index.jpg"; car4.carDetails=[NSArray arrayWithObjects:@"Harsha Mar05,2019",@"Registration AP2911234",@"Model Year 2009",@"CarModel Alto",@"Engine StreamEngine",@"Petrol Petrol",@"Exterior Color Black",@"interior Color Grey",@"Fuel Economy 1000",@"Insurance Insurance",@"Life time tax Free", nil]; Car *car5=[Car new]; car5.carName=@"Ritz"; car5.imageFile=@"Sport_Super_car.jpg"; car5.carDetails=[NSArray arrayWithObjects:@"Harsha Mar05,2019",@"Registration AP2911234",@"Model Year 2009",@"CarModel Alto",@"Engine StreamEngine",@"Petrol Petrol",@"Exterior Color Black",@"interior Color Grey",@"Fuel Economy 1000",@"Insurance Insurance",@"Life time tax Free", nil]; tableData=[NSArray arrayWithObjects:car1,car2,car3,car4,car5, nil]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section return [tableData count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier=@"CarCell"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } Car *car = [tableData objectAtIndex:indexPath.row]; cell.textLabel.text = car.carName; cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 78; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"showcardetails"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; CarDetailviewViewController *destViewController = segue.destinationViewController; destViewController.car = [tableData objectAtIndex:indexPath.row]; // Hide bottom tab bar in the detail view destViewController.hidesBottomBarWhenPushed = YES; } } </code></pre> <p><strong>CarDetailviewcontroller.m</strong></p> <pre><code>@synthesize carPhoto; @synthesize cardetailsTextView; @synthesize car; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = car.carName; self.carPhoto.image = [UIImage imageNamed:car.imageFile]; NSMutableString *ingredientText = [NSMutableString string]; for (NSString* ingredient in car.carDetails) { [ingredientText appendFormat:@"%@\n", ingredient]; } self.cardetailsTextView.text = ingredientText; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload