Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:17:23+00:00 2026-06-02T08:17:23+00:00

I am concerned with my 4 view controllers. The first one is the CardWalletViewController

  • 0

I am concerned with my 4 view controllers. The first one is the CardWalletViewController which is a table view that is populated by Card Objects that the user has created (the card creation is OK so I won’t post the code regarding that). Now, given that this table view is already populated with Card Objects, once the user clicks on a cell, another view controller, named CardDetailsViewController will show up. This will display the current points that the Card has and also the perks. Note that the current points is shown through a UILabel and the perks were a table view’s cells. This table view’s cell values(perks), are statically typed and are coming from a NSDictionary and then stored in an NSArray (for cell’s text display purpose). Now, when I click on a perk, the PerksDetailsViewController will show up. This contains UILabels which show the perk’s name and the points it requires. Those UILabels values were coming from the former ViewController. Also, PerksDetailsVC has a button named redeem. Upon clicking that I’ll proceed to another view controller, BarCodeViewController, which takes care of the computation.

Now my concern is on how to pass the selected Card, and also the points that corresponds to a selected perk. I’ve used delegation to do this but then it seems that my delegation object is not being set.

Below is my current code.

CardWalletViewController.h

#import <UIKit/UIKit.h>
#import "Card.h"

@class CardWalletViewController;

@protocol CardWalletDelegate <NSObject>

-(void)cardWalletViewController: (CardWalletViewController *)sender
                withCurrentCard: (Card *) currentCard;

@end

@interface CardWalletViewController : UITableViewController 

@property (nonatomic, strong) NSMutableArray *myWallet;

@property (nonatomic, weak) id <CardWalletDelegate> delegate;

@end  

CardWalletViewController.m

#import "CardWalletViewController.h"
#import "AddCardViewController.h"
#import "Card.h"
#import "CardDetailsViewController.h"

@interface CardWalletViewController ()

@end

@implementation CardWalletViewController

@synthesize delegate = _delegate;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    }
    Card *cardDummy = [self.myWallet objectAtIndex:indexPath.row]; //myWallet is an Array where the table cell's values come from
    cell.textLabel.text = cardDummy.name;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", cardDummy.points]; 

    return cell;
}

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

    //this method is responsible for showing the details of a selected card

    CardDetailsViewController *details = [self.storyboard instantiateViewControllerWithIdentifier:@"cardDetails"];


    Card *selectedCard = [self.myWallet objectAtIndex:indexPath.row]; // I want this selected card to be accessible until the user clicks another card or during end of program.

    details.myPoints = [NSString stringWithFormat:@"%@", selectedCard.points];

    [self.navigationController pushViewController:details animated:YES];


    [self.delegate cardWalletViewController:self withCurrentCard:selectedCard];

    //checking purposes
    if (!self.delegate) {
        NSLog(@"delegate is nil");
    }
}

CardDetailsViewController.m

#import "CardDetailsViewController.h"
#import "PerksDetailsViewController.h"
#import "Card.h"

@interface CardDetailsViewController ()

@end

@implementation CardDetailsViewController

@synthesize pointsLabel = _pointsLabel;
@synthesize myPoints  = _myPoints;

@synthesize perks = _perks;
@synthesize datasource = _datasource;
@synthesize datasourcePoints = _datasourcePoints;

-(void)setupArray
{
    self.perks = [[NSMutableDictionary alloc] init];
    [self.perks setObject:@"200" forKey:@"10% Discount"];
    [self.perks setObject:@"100" forKey:@"250Php Off"];

    self.datasource = [self.perks allKeys]; //contains perk's description
    self.datasourcePoints = [self.perks allValues]; //contains perk's required points
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

 cell.textLabel.text = [self.datasource objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [self.datasourcePoints objectAtIndex:indexPath.row];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PerksDetailsViewController *perksDetails = [self.storyboard instantiateViewControllerWithIdentifier:@"detailsOfMyPerks"];

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

    [super viewDidLoad];
}

PerksDetailsViewController.m

#import "PerksDetailsViewController.h"
#import "Card.h"
#import "CardWalletViewController.h"
#import "BarcodeViewController.h"

@interface PerksDetailsViewController ()

@end

@implementation PerksDetailsViewController

@synthesize pointsLabel = _pointsLabel;
@synthesize perkDetailsLabel = _perkDetailsLabel;
@synthesize perkDetailText = _perkDetailText;
@synthesize pointsText = _pointsText;
@synthesize delegate = _delegate;
@synthesize pointsRequired = _pointsRequired;


- (IBAction)redeemPressed:(id)sender {
    // get required points of a perk selected
    // cast the NSString value to an NSInteger

     NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
     [f setNumberStyle:NSNumberFormatterDecimalStyle];

     self.pointsRequired = [f numberFromString: (self.pointsLabel.text)];

    NSLog(@"points required by the perk %@", self.pointsRequired);

    [self.delegate perksDetailsViewController:self didPassRequiredPoints:self.pointsRequired];

    if (!self.delegate){
        NSLog(@"delegate is nil");
    }
}

PerksDetailsViewController.h

#import <UIKit/UIKit.h>
#import "BarcodeViewController.h"

@class PerksDetailsViewController;

@protocol PerksDetailsDelegate <NSObject>

- (void)perksDetailsViewController:(PerksDetailsViewController *)sender
             didPassRequiredPoints: (NSNumber *) requiredPoints;

@end

@interface PerksDetailsViewController : UIViewController
{
    NSString *perkDetailText;
    NSString *pointsText;
    IBOutlet UILabel *perkDetailsLabel;
    IBOutlet UILabel *pointsLabel;
}

@property (nonatomic, retain) IBOutlet UILabel *perkDetailsLabel, *pointsLabel;
@property (nonatomic, retain) NSString *perkDetailText, *pointsText;
@property (nonatomic, weak) NSNumber *pointsRequired;

@property (nonatomic, weak) id <PerksDetailsDelegate> delegate;

@end

Now this ViewController is the one that implements the two delegate methods

BarCodeViewController.h

#import <UIKit/UIKit.h>

@interface BarcodeViewController : UIViewController 

@property (nonatomic, strong) NSNumber *myPoints;

@end

BarCodeViewController.m

  #import "BarcodeViewController.h"
    #import "CardWalletViewController.h"
    #import "Card.h"
    #import "PerksDetailsViewController.h"

    @interface BarcodeViewController () <CardWalletDelegate, PerksDetailsDelegate>

    @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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:17:25+00:00Added an answer on June 2, 2026 at 8:17 am

    First of all, your delegate object property declaration

    @property (nonatomic, strong) id <PerksDetailsDelegate> delegate;
    

    should be changed from strong to weak, since your class doesn’t own it.

    Second, you never set the delegate object for your class. That’s the reason why it is nil. My guess is that BarCodeViewController (your PerksDetailsDelegate protocol implementing class) should be an instance variable of the CardDetailsViewController and you missed to set it as a delegate of the perksDetails object in didSelectRowAtIndexPath.

    Edit.

    You should have an instance of BarCodeViewController in the CardDetailsViewController class (named bcvController, for the example code below):

    CardDetailsViewController.m

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

    Edit 2

    BarCodeViewController.h

    #import <UIKit/UIKit.h>
    #import "CardWalletViewController.h"
    #import "Card.h"
    #import "PerksDetailsViewController.h"
    
    @interface BarcodeViewController : UIViewController <CardWalletDelegate, PerksDetailsDelegate>
    
    @property (nonatomic, strong) NSNumber *myPoints;
    
    @end
    

    BarCodeViewController.m

    #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
    

    Edit 3

    If you want to display a BarcodeViewController, you should use this object’s bcvController.

    CardDetailsViewController.m

    #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];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have one model & view that is served by multiple controllers
I'm trying to write an MSpec test that instantiates one of my controllers with
I have a project that has... I dunno... 200-300 daos/services/controllers and I use @Autowired
I have two view controllers. The CardWallet View Controller is my table view. Then
I have a view that I want to be converted into JSON. What is
I'm concerned that this is impossible, because +setAnimationDelegate: of UIView is a class method.
I'm concerned that when I use Facebook's feed dialog I'm making my App Id
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
In my app, I have a User model, which includes a number of attributes
I have an existing iPhone project that has been tested, submitted, and approved, compiled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.