Search code examples
iosobjective-csegueuivewcontroller

Data is not transferred to next view Controller


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog((@"This is didSelectRowAtIndexPAth"));
    DetailViewController *detailViewController = [[DetailViewController alloc] init];
    detailViewController.myDictionary = [self.placeArray objectAtIndex:[indexPath row]];

    /* The below NSlog is showing the content , its not null still in next viewcontroller same variable showing null content*/

    NSLog(@"My Dictionary: This is a MasterView%@",detailViewController.myDictionary);
    [self performSegueWithIdentifier:@"showDetail" sender:self];
}

Solution

  • try this
    

    Decalre one NSInteger varable Globaly assign that varble to indexpath.row

    @interface DashbordViewController ()
        {
    
            NSInteger       SelectedRownum;
    
        }
        @end
    
        @implementation DashbordViewController
        - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
        {
            self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
            if (self) {
                // Custom initialization
                   }
            return self;
        }
    
        - (void)viewDidLoad
        {
            [super viewDidLoad];
        }
    
             - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
            {
    
                    SelectedRownum=indexPath.row
                    [self performSegueWithIdentifier:@"showDetail" sender:self];
            }
    
            - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                {
    
                    if ([[segue identifier] isEqualToString:@"showDetail"])
                    {
    
                        NSLog((@"This is didSelectRowAtIndexPAth%@",SelectedRownum));
                        DetailViewController *detailViewController = [segue  destinationViewController];
                        detailViewController.myDictionary = [self.placeArray objectAtIndex:SelectedRownum];
    
    
                }
    
    
            }