not getting all images when passing images data to imageview - ios

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];
}
}

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];

segue not passing data over

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];

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];

How to use correctly segue with a Tab Bar Controller?

My application use a different master detail, its consist in an initial ViewController with a tableView, but when the user click the Add button in the navigation controller I need send an object using the follow function:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"AddDGV"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailView:object];
}
}
The code works fine when the destination is another ViewController, but my application was designed to have TabBarController instead a ViewController. This TabBar have 2 tabs, each one with a different Navigation Controller, and the first one is the target to the identifier "AddDGV". I created the .m/.h files and associated the class in the storyboard, and set the instance variable "DetailView" as ID.
#property (strong, nonatomic) id detailItem;
The problem is the compiler don't know this variable, because the command [segue destinationViewController] contains the view controller whose contents should be displayed at the end of the segue. As the end of the segue is a TabBarController, the function doesn't work.
Someone knows how fix it???
Typecast the output of
[segue destinationViewController]
as follows
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"AddDGV"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[(YourDestinationViewController *)[segue destinationViewController] setDetailView:object];
}
}

iOS - UIStoryboardSegue detecting table cell and opening a viewController?

So I have a UITableView, and the cells are connected to a UIStoryboardSegue in order to open a new UIViewController. After clicking a cell prepareForSegue get's called and everything works fine.
QUESTION: In the follwoing method how can i know what is the indexPath of the selected cell in my TableView?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ObjectDetailViewController *mvc = [segue destinationViewController];
// PassingObject *obj = [self.array objectAtIndex: ? ];
mvc.passingObject = obj;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Assume self.view is the table view
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
DetailObject *detail = [self detailForIndexPath:path];
[segue.destinationViewController setDetail:detail];
}
Instead of [self.tableView indexPathForSelectedRow] (look at the DJPlayer answer) you can use [self.tableView indexPathForCell:sender], since sender is a selected cell in this case.

Resources