segue not passing data over - ios

im still having problems with my segue
i have at the moment
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Check that a new transition has been requested to the DetailViewController and prepares for it
if ([segue.identifier isEqualToString:#"WeddingDetail"]){
// Capture the object (e.g. exam) the user has selected from the list
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *object = [self.objects objectAtIndex:indexPath.row];
// Set destination view controller to DetailViewController to avoid the NavigationViewController in the middle (if you have it embedded into a navigation controller, if not ignore that part)
UINavigationController *nav = [segue destinationViewController];
DMKWeddingDetailViewController *detailViewController = (DMKWeddingDetailViewController *) nav.nextResponder;
detailViewController.exam = object;
NSLog(#"object details: %#",object);
}
}
i was hoping that exam would hold the data but it isnt the data is held in object. but not sure how to pass object over to detail view controller.
in my detailview controller i have a list if textlabels
self.name.text = [self.exam objectForKey:#"name"];
but they are not populating

in case that the destination ViewController is a UINavigationController, I think the problem is in
DMKWeddingDetailViewController *detailViewController = (DMKWeddingDetailViewController *) nav.nextResponder;
you should use this instead
DMKWeddingDetailViewController *detailViewController = (DMKWeddingDetailViewController *) [nav topViewController];
and if the destination is your target ViewController you should use
DMKWeddingDetailViewController *detailViewController = (DMKWeddingDetailViewController *) [segue destinationViewController];

Related

How pass core data value from tableview to another view

I'm trying to pass data from one table view to another view. Both is the same core data. I just need to make another view to show the correct data according the selected table. Here is the code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetailTwo"]) {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
[self.tableView deselectRowAtIndexPath:path animated:YES];
DetailViewController *moviewDetailVC = [segue destinationViewController];
NSManagedObject *movies=[self.moviesArray objectAtIndex:path.row];
// NSLog(#"%#", movies);
Movies *movieL =[NSKeyedUnarchiver unarchiveObjectWithData:[movies valueForKey:#"posterImage"]];
[moviewDetailVC.movieSelected setPosterImage: movieL];
}
}
But when I go to next screen the data is null
2016-08-11 23:12:02.020 OMBDSearch[20175:1682899] (null)
I'm new at core data so I need a little help. I've searched a lot for this and didn't solve my problem.
I was trying to do in a difficult way. This way solve my question:
DetailViewController *destination = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
destination.movieSelected = [self.moviesArray objectAtIndex:indexPath.row];

not getting all images when passing images data to imageview

I am parsing xml image urls to imageview in detailviewcontroller but I passed the images through the shareddelegate.but when i click on the tableviewcell only few images occure in detailviewcontroller.
imageview.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:sharedDelegate.imagObj]]];
the above code I wrote in detailviewcontroller
AppDelegate *sharedDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
sharedDelegate.imagObj = [Imagesarray objectAtIndex:indexPath.row];
I wrote this code in tableview didselectrow method.
It would make your code easier to read and maintain, if you pass the data to your detailViewController in a property.
This will help detailViewController to be more self-contained, and limit what it can mutate.
Add a property to your DetailViewController for the data you want to pass. It sounds like you want to pass an array of image URLs, so add an array property:
#property (nonatomic, strong) NSArray *images;
In prepareForSegue:sender:, set the DetailViewController's passed images to the values associated with the selected row:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)__unused sender
{
if ([[segue identifier] isEqualToString:#"showDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *controller = (DetailViewController *)[segue destinationViewController];
controller.images = ...;
}
}
You don't need to have a tableView:didSelectRowAtIndexPath: method, if you create a push segue from a tableViewCell to DetailViewController within Storyboard. Give the segue an identifier (such as "showDetail"). Then in prepareForSegue, you pass the necessary data, as mentioned.
You can create a image property in DetailViewController
And from tableview didSelectRowAtIndexPath method. call the segue
[self performSegueWithIdentifier:#"DetailSegue" sender:indexpath];
and set it from
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"DetailSegue"])
{
DetailViewController *dc = (DetailViewController *)[segue destinationViewController];
dc.image = [imagesarray objectAtIndex:sender.row];
}
}

Issue with PFObject

I need to pass a PFObject to 2 views, first one is detail and second is a segue from the detail. I can easily pass the PFObject to the detail, using PFObject *obj = [array objectAtIndex:indexPath.row], detailVC.object = object in prepareForSegue to a property of the detail view controller, but when I try to pass from the detail to the third view, using vc.object = self.object in prepareForSegue then the value of the PFObject in third view is nil. What is the problem?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"segue"]) {
thirdVC *vc = (thirdVC *)segue.destinationViewController;
vc.object = self.object;
}
}
I often found this error when I tried to segue to a VC embedded within its own navigation controller. Make sure it is not, and if it is use this to refer to the controller instead
if ([segue.identifier isEqualToString:#"<#Segue Name#>"]) {
UINavigationController *nav = (UINavigationController *)[segue destinationViewController];
<#UIViewController#> *controller = (<#UIViewController#> *)nav.topViewController;
controller.object = self.object;
}
Other than that, I can only think to log the object inside the second VC's prepareForSegue and see if it exists there

how to push subtitle from uitableview to detail view controller

i have a project which is basically a uitableview populated with a mutable array and has a search bar
now the uitableview has title and subtitle which are populated with different mutable arrays ..
when you tap on a cell (from the view or from the search view) it pushes the title to a new view controller.
i need the subtitle to be pushed also to the new view controller
i tried every thing i know but i had no success
i have attached the project so you can see how its coded and possibly tell me how to fix it
http://ezzati.net/KuwaitFood.zip
please help
Please replace the function below.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ShowDetail"]) {
NSString *object = nil;
NSIndexPath *indexPath = nil;
if (self.searchDisplayController.isActive) {
indexPath = [[self.searchDisplayController searchResultsTableView] indexPathForSelectedRow];
object = self.results[indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
object = self.objects[indexPath.row];
}
[[segue destinationViewController] setDetailLabelContents:object];
[[segue destinationViewController] setNumberdetailLabelContents:[sender detailTextLabel].text];
}
}
You have to assign a identifier to the segue (the arrow from your table view controller to the new controller in your storyboard) and then use this function to grab the destination view controller and set it's property with the data you want to send:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"identifier"])
{
SecondViewController *vc = [segue destinationViewController];
// get the selected item index
NSInteger index = [self.tableView indexPathForCell:sender].row;
// set the data property for the second view (pass data)
vc.theProperty = [self.data objectAtIndex:index];
}
Now you can find theProperty on your SecondViewController filled with data from the table view controller.
EDIT: I've reviewed your code. for your case do this:
in -tableView: didSelectRowAtIndexPath: change self to indexPath like this:
[self performSegueWithIdentifier:#"ShowDetail" sender:indexPath];
and in prepareForSegue do this:
DetailViewController *vc = [segue destinationViewController];
// get the selected item index
NSInteger index = ((NSIndexPath *)sender).row;
// index of searched object in self.objects
NSInteger trueIndex = [self.objects indexOfObject:[self.results objectAtIndex:index]];
// set the data property for the second view (pass data)
vc.detailLabelContents = [self.objects objectAtIndex:trueIndex];
vc.numberdetailLabelContents = [self.numbers objectAtIndex:trueIndex];
the problem was because you were using index of self.results and applying it to self.objects which was 0, so you were always getting the first object "You Tube"
change the last line of
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
as below
[[segue destinationViewController] setDetailLabelContents:[sender detailTextLabel].text];

Unable to segue using an accessory indicator

I have a segue with three transitions (see code below). The first from a button. That works perfectly. The second by tapping on the cell in a table view. That one works perfectly too. The third is an accessory button in the tableview cell. This one opens the proper view controller, but does not pass a reference to the patient as I have coded. I have verified this by an NSLog statement in the viewDidLoad of the new view controller and it shows patient as being null.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"addPatient"]) {
// to add a new patient (selection segue)
UINavigationController *navigationController = segue.destinationViewController;
RXAddPatientViewController *addPatientViewController = (RXAddPatientViewController*)navigationController.topViewController;
Patient *addPatient = [NSEntityDescription insertNewObjectForEntityForName:#"Patient" inManagedObjectContext:[self managedObjectContext]];
addPatientViewController.addPatient = addPatient;
}
if ([[segue identifier] isEqualToString:#"toPrescriptions"]) {
// to view prescriptions for the selected patient (selection segue)
RXPrescriptionsViewController *prescriptionViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Patient *selectedPatient = (Patient*) [self.fetchedResultsController objectAtIndexPath:indexPath];
prescriptionViewController.selectedPatient = selectedPatient;
NSLog(#"Selected Patient is %#", selectedPatient.patientFirstName);
}
if ([[segue identifier] isEqualToString:#"editPatient"]) {
// to edit the selected patient (accessory action)
UINavigationController *navigationController = segue.destinationViewController;
RXEditPatientViewController *editPatientViewController = (RXEditPatientViewController*)navigationController.topViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Patient *editPatient = (Patient*) [self.fetchedResultsController objectAtIndexPath:indexPath];
// passing a reference to the editPatientViewController
editPatientViewController.editPatient = editPatient;
NSLog(#"Selected patient is %#", editPatient.patientFirstName);
}
}
The indexPathForSelectedRow will be null when you click on the accessory button because you're not selecting the row. However, the sender argument in prepareForSegue:sender: will be the cell that the accessory button is contained in. So, you should use the following method to get the indexPath (notice that I changed the typing of the argument to UITableViewCell from id):
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender {
if ([[segue identifier] isEqualToString:#"editPatient"]) {
// to edit the selected patient (accessory action)
UINavigationController *navigationController = segue.destinationViewController;
RXEditPatientViewController *editPatientViewController = (RXEditPatientViewController*)navigationController.topViewController;
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
Patient *editPatient = (Patient*) [self.fetchedResultsController objectAtIndexPath:indexPath];
// passing a reference to the editPatientViewController
editPatientViewController.editPatient = editPatient;
NSLog(#"Selected patient is %#", editPatient.patientFirstName);
}

Resources