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 7847299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:51:07+00:00 2026-06-02T17:51:07+00:00

I have a Card Object, which have 4 instance variables namely name(NSString), pin(NSString), points(NSNumber),

  • 0

I have a Card Object, which have 4 instance variables namely name(NSString), pin(NSString), points(NSNumber), pointsToDeduct(NSMutableArray).

Card.h

@interface Card : NSObject

    @property (nonatomic, strong) NSString *name;
    @property (nonatomic, strong) NSString *pin;
    @property (nonatomic, strong) NSNumber *points;
    @property (nonatomic, strong) NSMutableArray *pointsToDeduct;

@end

This pointsToDeduct array is always present for every new instance of Card I make. What I want is to fill it’s values with another array’s values which are static through a button click. But before that, in my code below, I cast those static values into an NSNumber so that the pointsToDeduct’s values will be of type NSNumber. I’m thinking of delegation to do this though not sure if it’s best. For now I want to access that pointsToDeduct array so I can add values in it.

*this is part of PerksDetailsViewController.m

- (IBAction)redeemPressed:(id)sender {

     NSNumber *pointsRequired;
     NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
     [formatter setNumberStyle:NSNumberFormatterDecimalStyle];

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

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

    // now insert pointsRequired's value to pointsToDeduct array instance variable of a Card

Below are the other codes that I have.

Main View
CardWalletViewController.h

#import <UIKit/UIKit.h>

@interface CardWalletViewController : UITableViewController 

@property (nonatomic, strong) NSMutableArray *myWallet;

-(void) printArrayContents;

CardWalletViewController.m

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

@interface CardWalletViewController () <AddCardDelegate>

@end

@implementation CardWalletViewController


@synthesize myWallet = _myWallet;

- (NSMutableArray *) myWallet
{
    if (_myWallet == nil) _myWallet = [[NSMutableArray alloc] init]; 
    return _myWallet;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showAddCardVC"]) {
        AddCardViewController *addCardVC = (AddCardViewController *)segue.destinationViewController;

        addCardVC.delegate = self;

    }
}

- (void)printArrayContents 
{

    // I want to show the name of each instance

    for ( int i = 0; i < self.myWallet.count; i++) {
        Card *cardDummy = [self.myWallet objectAtIndex:i];
        NSLog(@"Element %i is %@", i,cardDummy.name );
    }
}

- (void)addCardViewController:(AddCardViewController *)sender didCreateCard:(Card *)newCard
{
    // insert a new card to the array

    [self.myWallet addObject:newCard];

    [self printArrayContents];
    [self.tableView reloadData];
}

- (void)saveMyWallet: (NSMutableArray *)myWallet
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject:self.myWallet forKey:@"myWalletArray"];

    [defaults synchronize];
    NSLog(@"I am saved");
}


- (NSMutableArray *)loadWallet 
 {
    NSMutableArray *boom;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    boom = [defaults objectForKey: @"myWalletArray"];

    if (!boom) {
        boom = [[NSMutableArray alloc] init];
    }



 return boom;

}

- (void)viewDidLoad
{
    [self loadWallet];
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //this method will return the number of rows to be shown
    return self.myWallet.count;
}

- (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];
    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
    //make another view controller - DetailVC perhaps

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


    Card *cardDummy = [self.myWallet objectAtIndex:indexPath.row];

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

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



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

The way I create a new Card

AddCardViewController.m

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

@interface AddCardViewController ()

@end

@implementation AddCardViewController 

@synthesize cardNameTextField = _cardNameTextField;
@synthesize pinTextField = _pinTextField;
@synthesize pointsTextField = _pointsTextField;

@synthesize delegate = _delegate;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.cardNameTextField becomeFirstResponder];


}    

- (BOOL) textFieldShouldReturn:(UITextField *)textField{

    if ([textField.text length]) {
    [self.cardNameTextField resignFirstResponder];

    [self.pinTextField resignFirstResponder];

    [self.pointsTextField resignFirstResponder];

    return YES;
    }

    else {
        return NO;
    }
}

- (void)viewDidLoad
{
    self.cardNameTextField.delegate = self;
    self.pinTextField.delegate = self;
    self.pointsTextField.delegate = self;
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setCardNameTextField:nil];
    [self setPinTextField:nil];
    [self setPointsTextField:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)addCard:(id)sender 
{
    Card *myNewCard = [[Card alloc] init];


    myNewCard.name = self.cardNameTextField.text;

    myNewCard.pin = self.pinTextField.text;


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

    myPoints = [f numberFromString: (self.pointsTextField.text)];

    myNewCard.points = myPoints;


    //method here that will dismiss the modal view
    // if condition forces the user to fill up all the text field

    if ([self.cardNameTextField.text length] && [self.pinTextField.text length] && [self.pointsTextField.text length]) 
    {
        //method here that will dismiss the modal view
        [[self presentingViewController] dismissModalViewControllerAnimated:YES];


        //checking...
        NSLog(@"name saved %@", myNewCard.name);
        NSLog(@"pin saved %@", myNewCard.pin);
        NSLog(@"points saved %@", myNewCard.points);

        [self.delegate addCardViewController:self didCreateCard:myNewCard];

        // to check if there is a delegate
        /*
         if (self.delegate){
            NSLog(@"delegate is not nil");
        }
         */
    }
}

@end

AddCardViewController.h

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

@class AddCardViewController;

@protocol AddCardDelegate <NSObject>

- (void)addCardViewController:(AddCardViewController *)sender
                didCreateCard:(Card *) newCard;

@end


@interface AddCardViewController : UIViewController <UITextFieldDelegate>


@property (strong, nonatomic) IBOutlet UITextField *cardNameTextField;
@property (strong, nonatomic) IBOutlet UITextField *pinTextField;
@property (strong, nonatomic) IBOutlet UITextField *pointsTextField;

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

@end

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.navigationItem.title = @"Your Points";

    [self setupArray];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setPointsLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

@end

CardDetailsViewController.h

#import <UIKit/UIKit.h>

@interface CardDetailsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> 
{

}

@property (nonatomic, retain) NSMutableDictionary *perks;
@property (nonatomic, retain) NSArray *datasource;
@property (nonatomic, retain) NSArray *datasourcePoints;

-(void)setupArray;

@property (strong, nonatomic) IBOutlet UILabel *pointsLabel;
@property (nonatomic, weak) NSString *myPoints;

@end

PerksDetailsViewController.m

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

@interface PerksDetailsViewController ()

@end

@implementation PerksDetailsViewController

@synthesize pointsLabel = _pointsLabel;
@synthesize perkDetailsLabel = _perkDetailsLabel;
@synthesize perkDetailText = _perkDetailText;
@synthesize pointsText = _pointsText;

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

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

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

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

    // now insert this value to points array instance variable of a Card        

}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    //self.perkDetailsLabel.text = self.perkDetailText;
    //self.pointsLabel.text = self.pointsText;
    NSLog(@"perk detail:%@", self.perkDetailText);
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setPerkDetailsLabel:nil];
    [self setPointsLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

PerksDetailsViewController.h

#import <UIKit/UIKit.h>

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

@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-02T17:51:10+00:00Added an answer on June 2, 2026 at 5:51 pm

    Your PerksDetailViewController needs to have a property of the current Card object. Then, it’s simply a matter of

    [self.card.pointsToDeduct addObject:pointsRequired];
    

    I can’t see in all your sample code where you are actually using any Card objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small card game for Google+ which needs the visitor's name, avatar,
I have a CERT_CONTEXT structure which I've extracted from a smart card on Windows
I have a Tuple<T1, T2> which contains the same object that are in a
I have classes Pile which represents a card deck, and so contains instances of
I have an application which I usually run on Nvidia graphics card. I thought
I have a Deck object (deck of cards) which is a double-ended queue implemented
We have a site in ColdFusion which integrates with a credit card provider using
I have a Card class and I want to overload the > operator to
If I have a Visa card number saved in my database, is there a
Even though I have a fermi card(gtx 560) I get this error on VS2010:

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.