I want to pass PFObject from VC1 to VC2. I know thats easy if I pass PFObject from Tableview to VC. Anyway, I have A VC with Tableview with the segue to detailVC (1) with ImageView. This ImageView would be shown in detailiamgeviewcontroller after tap image.(2) And I want to send pfobject to this Controller. But have no idea how to.
Any idea?
(1)
if ([segue.identifier isEqualToString:#"showDetaill"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *object = [self.objects objectAtIndex:indexPath.row];
DetailViewController2 *detailViewController = [segue destinationViewController];
detailViewController.objecteditem = object;
}
(2)
- (void)viewDidLoad
{
[super viewDidLoad];
[self.imageviewsecond setImageWithURL:[NSURL URLWithString:[self.objecteditem objectForKey:#"VlajkaURL"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
UITapGestureRecognizer *singleTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
singleTap.numberOfTapsRequired = 1;
[imageviewsecond addGestureRecognizer:singleTap];
}
- (void)handleSingleTap:(UIGestureRecognizer *)sender
{
[self performSegueWithIdentifier:#"sendi" sender:self];
NSLog(#"image tapped!!!");
}
Do the same as you are already doing. In view 1 you are sending the object to view 2 (DetailViewController2). In DetailViewController2, in the prepareForSegue method, you do the same:
if ([segue.identifier isEqualToString:#"sendi"])
{
DetailImageViewController *detailImageViewController = [segue destinationViewController];
detailImageViewController.somePropertyName = self.objecteditem;
}
Related
I went from one ViewController to another using Segue in my second viewController has an UITableView. now, I want to push from second ViewController's didSelected method to another viewController.
code use to Segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
SearchVC *svc = segue.destinationViewController;
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
}
under button action:
-(void) searchButtonClicked:(id)sender {
[self performSegueWithIdentifier:#"search" sender:nil];
}
And the main problem arise here, can't navigate using below code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PackageListVC *pdvc = (PackageListVC *)[self.storyboard instantiateViewControllerWithIdentifier:#"PackageListVC"];
pdvc.strServiceProviderId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"ServiceProviderId"] stringValue];
pdvc.strCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"CategoryId"] stringValue];
pdvc.strSubCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"SubCategoryId"] stringValue];
pdvc.strTitle = [[arrSearch objectAtIndex:indexPath.row] objectForKey:#"CompanyName"];
[self.navigationController pushViewController:pdvc animated:YES];
}
You do it in the prepareForSegue method.
where you declare svc (SearchVC *svc = segue.destinationViewController;) you can say something like:
svc.variable = 1;
I know this question is asked many time , i had searched a lot and tried many solution but not worked. I have made a customize table view in which data is load from a service. The data load is quite limited , i have to show the detail of data into new view controller when user click on a cell. Its should pass data of the respective cell which carries data. I have tried segue technique to pass data to new vc but fails , its shows null in value which i'm passing. I have created some labels in new vc in which i'm calling the values from table view cell. My code is,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowDetail"]) {
//Do something
ShowViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
destViewController.tites = [_Title objectAtIndex:indexPath.row];
destViewController.prce = [_Price objectAtIndex:indexPath.row];
NSLog(#"PPPP is %#",destViewController.phon);
destViewController.ara = [_LandArea objectAtIndex:indexPath.row];
destViewController.phon = [_Phone objectAtIndex:indexPath.row];
destViewController.citi = [_City objectAtIndex:indexPath.row];
destViewController.loc = [_location objectAtIndex:indexPath.row];
destViewController.tye = [_type objectAtIndex:indexPath.row];
destViewController.Idss = [_Id objectAtIndex:indexPath.row];
destViewController.nam = [_name objectAtIndex:indexPath.row];
destViewController.emal = [_email objectAtIndex:indexPath.row];
destViewController.roomss = [_rooms objectAtIndex:indexPath.row];
destViewController.wash = [_washroom objectAtIndex:indexPath.row];
destViewController.flloors = [_floor objectAtIndex:indexPath.row];
destViewController.stat = [_status objectAtIndex:indexPath.row];
destViewController.descrp = [_descrip objectAtIndex:indexPath.row];
destViewController.countryy = [_country objectAtIndex:indexPath.row];
}
}
Issue in this question is that you are not populating the _Price and other arrays properly, so where you are populating _Title array , fill other arrays as well like _Price, _City
An outlet doesn't instantiate because an outlet is a variable (or property).
The objects in a nib are instantiated when that nib is loaded, and they are assigned to each outlet as immediately as possible afterward, after the objects are created but before awakeFromNib is sent to all relevant objects.
In your case you can pass data in ShowViewController and update the label in ShowViewController's viewDidLoad or viewDidAppear.
Define string in ShowViewController interface as
#property (strong, nonatomic) NSString * titesStr;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowDetail"]) {
//Do something
ShowViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
destViewController.titesStr = [_Title objectAtIndex:indexPath.row];
....
....
....
}
}
In ShowViewController viewDidAppear update your label as
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
tites.text = titesStr;
}
In place of passing data one by one you can use array also. Best implementation would be using model class.
EDIT
[self performSegueWithIdentifier:#"ShowDetail" sender:tableView];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowDetail"]) {
//Do something
UITableView *tv = (UITableView*)sender;
ShowViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [tv indexPathForSelectedRow];
destViewController.tites = [_Title objectAtIndex:indexPath.row];
....
....
....
}
}
Make following changes in your code :
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"ShowDetail" sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"ShowDetail"])
{
ShowViewController *destViewController =(ShowViewController *) segue.destinationViewController;
NSIndexPath *indexPath = (NSIndexPath *)sender;
destViewController.tites = [_Title objectAtIndex:indexPath.row];
destViewController.prce = [_Price objectAtIndex:indexPath.row];
// use this indexpath for segue
}
}
I have an unwind segue that i am using, and then i have a prepare for segue that i am using to push data.
I need the unwind segue to push the data but i am having issues combining them.
Here is the unwind segue code -
- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue {
// ViewController *detailViewController = [segue sourceViewController];
NSLog(#"%#", segue.identifier);
}
And here is the prepare for segue code -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
NSIndexPath *indexPath = nil;
Recipe *recipe = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
recipe = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
recipe = [recipes objectAtIndex:indexPath.row];
}
PersonDetailTVC *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
And here is what i tried which is unwinding the segue, but not pushing the data.
- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue {
if ([segue.identifier isEqualToString:#"CustomTableCell"]) {
NSIndexPath *indexPath = nil;
Recipe *recipe = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
recipe = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
recipe = [recipes objectAtIndex:indexPath.row];
}
PersonDetailTVC *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Your question's rather incomplete so I can only answer based on assumptions...
First off, this method should be in the view controller you're returning to.
- (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue {
}
Secondly, use your prepareForSegue: method, not your unwindFromDetailViewController: method (which belongs in the first view controller), to pass your data from that second view controller. I believe though that you're using your forward segue's identifier and not your unwind segue's identifier in your if ([segue.identifier isEqualToString:#"showRecipeDetail"]) statement, that it's therefore returning false, and thus that entire block in your prepareForSegue: method isn't executing at all. (This line: [self dismissViewControllerAnimated:YES completion:nil]; is complete unnecessary since the unwind occurs automatically as long as everything's hooked up correctly.) So try removing the conditional for now just to see if the data is passed as expected, ex:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = nil;
Recipe *recipe = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
recipe = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
recipe = [recipes objectAtIndex:indexPath.row];
}
PersonDetailTVC *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
}
If you want to re-add a conditional specifying a check for your segue's identifier, you have to set an identifier specifically for the unwind segue.
I am solving this issue about 2 weeks and only be able to pass string, not image.
I store the image from camera or from library in this method.
-(IBAction)saveAction:(id)sender
{
Tricks *trick = [[Tricks alloc]init];
trick.trickName = self.trickLabel.text;
trick.trickPhoto = [[UIImageView alloc] initWithFrame:CGRectMake(0, 356, 320, 305)];
trick.trickPhoto.image = self.ImagePhoto.image;
[[Tricks trickList]addObject:trick];
}
In tableViewClass I store the values into properties of detailView
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"detailTrick"]){
NSIndexPath *indexPath = nil;
indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
Tricks *trick = [[Tricks trickList] objectAtIndex:indexPath.row];
detailViewController.trickPhoto = [[UIImageView alloc]initWithFrame:CGRectMake(0, 358, 200, 200)];
detailViewController.fileText = trick.trickName;
detailViewController.trickPhoto = trick.trickPhoto;
//object = [Tricks trickList][indexPath.row]
}
}
Text showed up every time without problems, but there is no image in detailViewController.Thanks for help.
viewDidLoad of detailViewController
[super viewDidLoad];
[self.detailButton setTitle:[NSString stringWithFormat:#"%#",_fileText] forState:UIControlStateNormal];
[self.trickPhoto setImage:_trickPhoto.image];
First off, trickPhoto within the Trick class should be a UIImage, not a UIImageView. Models shouldn't know anything about views such as frames, etc so right now you're violating the MVC design pattern.
Then it'd be:
- (IBAction)saveAction:(id)sender
{
Tricks *trick = [[Tricks alloc] init];
trick.trickName = self.trickLabel.text;
trick.trickPhoto = self.ImagePhoto.image;
[[Tricks trickList] addObject:trick];
}
The better way of doing this would be to create a Trick property within DetailViewController and just pass the whole trick into the view controller.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"detailTrick"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
Tricks *trick = [[Tricks trickList] objectAtIndex:indexPath.row];
NSLog(#"Make sure trick isn't nil: %#", trick);
detailViewController.trick = trick;
}
}
Then you'd just populate it with:
[super viewDidLoad];
[self.detailButton setTitle:[NSString stringWithFormat:#"%#", self.trick.trickName] forState:UIControlStateNormal];
[self.trickPhoto setImage:self.trick.trickPhoto];
I am just trying to transfer a simple string from a UILabel in a prototype cell into a label in the next View Controller. Value of label.text in the viewDidLoad of the View Controller is returning (null).
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
mainCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (mainCell == nil) {
mainCell = [[dictionaryTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString* date = [dateArray objectAtIndex:indexPath.row];
mainCell.viewLabel.text = date;
return mainCell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"View Segue"]) {
NSLog(#"View Load Segue Success");
ViewController *one = segue.destinationViewController;
one.label.text = mainCell.viewLabel.text;
}
}
What am I doing wrong here?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"View Segue"]) {
NSLog(#"View Load Segue Success");
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ViewController *one = segue.destinationViewController;
one.label.text = [dateArray objectAtIndex:indexPath.row];
}
}
And actually, assigning text to text label you should do in your viewController one's method(viewDidLoad or viewWillAppear). So, you need to make a property in viewController one for transferring NSString.
You can use indexPathForSelectedRow:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"View Segue"]) {
ViewController *one = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
one.textProperty = [dateArray objectAtIndex:indexPath.row];
}
}
Or you can also use sender if your segue is from the cell to the next scene, e.g.:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"View Segue"])
{
ViewController *one = segue.destinationViewController;
NSAssert([sender isKindOfClass:[UITableViewCell class]], #"Not cell");
UITableViewCell *cell = sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
one.textProperty = [dateArray objectAtIndex:indexPath.row];
}
}
Two things to note:
As a matter of good programming style, I am not retrieving the text value from the cell. I'm retrieving the text value from the model. You should not be relying upon the view for information to be passed along. Go back to the model, the original source of the information.
Do not set the text property of the label in the destination controller directly. The controls of the destinationController have not been created yet. You should defer setting controls until the destinationController's viewDidLoad. So, instead, create a NSString property in the destination controller:
#property (nonatomic, strong) NSString *textProperty;
Clearly, you should use a more descriptive name than textProperty, but hopefully you get the idea. Anyway, prepareForSegue can set this new property and the viewDidLoad of the destination controller should then use that NSString property to populate the text property of the UILabel, e.g.:
- (void)viewDidLoad
{
[super viewDidLoad];
self.label.text = self.textProperty;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YourViewController *controller =[[YourViewController alloc] init];
[self presentModalViewController:controller animated:YES];
one.label.text = [dateArray objectAtIndex:indexPath.row];
}
Change the label.text after presentModalViewController. Now what happens?
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion
I understand you are already using Segue. You should follow the other answer.