Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, your delegate object property declaration</p> <pre><code>@property (nonatomic, strong) id &lt;PerksDetailsDelegate&gt; delegate; </code></pre> <p>should be changed from <code>strong</code> to <code>weak</code>, since your class doesn't own it.</p> <p>Second, you never set the delegate object for your class. That's the reason why it is <code>nil</code>. My guess is that <code>BarCodeViewController</code> (your <code>PerksDetailsDelegate</code> protocol implementing class) should be an instance variable of the <code>CardDetailsViewController</code> and you missed to set it as a delegate of the <code>perksDetails</code> object in <code>didSelectRowAtIndexPath</code>.</p> <p>Edit.</p> <p>You should have an instance of <code>BarCodeViewController</code> in the <code>CardDetailsViewController</code> class (named <code>bcvController</code>, for the example code below):</p> <p><code>CardDetailsViewController.m</code></p> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { PerksDetailsViewController *perksDetails = [self.storyboard instantiateViewControllerWithIdentifier:@"detailsOfMyPerks"]; [perksDetails setDelegate:bcvController]; // bcvController should be created before this line [self.navigationController pushViewController:perksDetails animated:YES]; perksDetails.perkDetailsLabel.text = [self.datasource objectAtIndex:indexPath.row]; perksDetails.pointsLabel.text = [self.perks objectForKey:perksDetails.perkDetailsLabel.text]; } </code></pre> <h1>Edit 2</h1> <p>BarCodeViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "CardWalletViewController.h" #import "Card.h" #import "PerksDetailsViewController.h" @interface BarcodeViewController : UIViewController &lt;CardWalletDelegate, PerksDetailsDelegate&gt; @property (nonatomic, strong) NSNumber *myPoints; @end </code></pre> <p>BarCodeViewController.m</p> <pre><code>#import "BarcodeViewController.h" // @interface BarcodeViewController () // // @end @implementation BarcodeViewController @synthesize myPoints = _myPoints; - (void)perksDetailsViewController:(PerksDetailsViewController *)sender didPassRequiredPoints:(NSNumber *)requiredPoints { self.myPoints = requiredPoints; } - (void)cardWalletViewController:(CardWalletViewController *)sender withCurrentCard:(Card *)currentCard { Card *myCurrentCard = currentCard; [myCurrentCard.pointsToDeduct addObject:self.myPoints]; NSLog(@"contents :%@", [myCurrentCard.pointsToDeduct description]); } @end </code></pre> <h1>Edit 3</h1> <p>If you want to display a BarcodeViewController, you should use this object's bcvController.</p> <p>CardDetailsViewController.m</p> <pre><code>#import "CardDetailsViewController.h" #import "PerksDetailsViewController.h" #import "Card.h" @implementation CardDetailsViewController @synthesize pointsLabel = _pointsLabel; @synthesize myPoints = _myPoints; @synthesize perks = _perks; @synthesize datasource = _datasource; @synthesize datasourcePoints = _datasourcePoints; @synthesize bcvController = _bcvController; // new instance variable // other functions removed for clarity -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { PerksDetailsViewController *perksDetails = [self.storyboard instantiateViewControllerWithIdentifier:@"detailsOfMyPerks"]; [perksDetails setDelegate:bcvController]; [self.navigationController pushViewController:perksDetails animated:YES]; perksDetails.perkDetailsLabel.text = [self.datasource objectAtIndex:indexPath.row]; perksDetails.pointsLabel.text = [self.perks objectForKey:perksDetails.perkDetailsLabel.text]; } - (void)viewDidLoad { //show the number of points of the selected Card self.pointsLabel.text = self.myPoints; [self setupArray]; [self setBcvController:[self.storyboard instantiateViewControllerWithIdentifier:@"myBarcodeVC"]]; // use setter to retain object properly [super viewDidLoad]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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