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

  • Home
  • SEARCH
  • 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 928321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:59:30+00:00 2026-05-15T19:59:30+00:00

I have a Card class subclassed from UIView and a Deck class from NSObject.

  • 0

I have a Card class subclassed from UIView and a Deck class from NSObject. Card has a few integer properties on top of the inherited UIView ones and Deck has an NSMutableArray for holding some cards. After generating a deck of cards, I want to display a randomly selected card (by adding it to the superview). Before I do, I check to see if there is a card already, I call a method to release it before asking for a new one. But I get the warning in the title. Here’s the code…


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

@interface FlashTestViewController : UIViewController {

Deck*       aDeck;
Card*       aCard;
}

- (IBAction)generateDeck;
- (IBAction)generateCard;
- (void)fadeAway:(id)sender;

@end

#import "FlashTestViewController.h"

@implementation FlashTestViewController

- (IBAction)generateDeck {

    if (aDeck != nil) {
        [aDeck release];
    }

    aDeck = [[Deck alloc] initDeckWithOperator:@"+"];
}


- (IBAction)generateCard {

    if (aCard != nil) {
        [aCard fadeAway];
    }

    aCard = [aDeck newCardFromDeck];
    [self.view addSubview:aCard];
}

- (void)fadeAway:(id)sender {
    [aCard removeFromSuperview];
    [aCard release];
    }

I am a beginner at programming (other than Basic!) so I’m still wrapping my head around the whole object thing. Thanks for any help and/or advice!

EDIT:
Here’s the Card and Deck code…


#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@class Card;

@interface Card : UIView {

int         upperOperand;
int         lowerOperand;
NSString*   theOperator;
int         theResult;
}

@property(nonatomic) int upperOperand;
@property(nonatomic) int lowerOperand;
@property(nonatomic, retain) NSString* theOperator;
@property(nonatomic) int theResult;

@end

#import "Card.h"


@implementation Card

@synthesize upperOperand;
@synthesize lowerOperand;
@synthesize theOperator;
@synthesize theResult;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
    // Initialization code
    self.backgroundColor = [UIColor redColor];
    self.layer.cornerRadius = 15;
    self.alpha = 0.3;
    self.layer.borderColor = [[UIColor blueColor] CGColor];
    self.layer.borderWidth = 4;
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

@end

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

@class Deck;

@interface Deck : NSObject {

NSMutableArray* cards;
}

@property(nonatomic, retain) NSMutableArray* cards;

- (id)initDeckWithOperator: (NSString*)mathOper;
- (id)newCardFromDeck;

@end

#import "Deck.h"

@implementation Deck

@synthesize cards;

- (id)initDeckWithOperator: (NSString*)mathOper {
    if (cards != nil) {
    [cards release];
    }
    cards = [[NSMutableArray alloc] init];
    for (int i=0; i<11; i++) {
        for (int j=0; j<11; j++) {
            Card* aCard = [[Card alloc] initWithFrame:CGRectMake(10, 10, 60, 80)];
            aCard.upperOperand = i;
            aCard.lowerOperand = j;
            aCard.theOperator = mathOper;
            aCard.theResult = i + j;
            [cards addObject: aCard];
            [aCard release];
        }
    }
    return self;
}

- (id)newCardFromDeck {
    int index = random() % [cards count];
    Card* selectedCard = [[cards objectAtIndex:index] retain];
    [cards removeObjectAtIndex:index];
    return selectedCard;
}

@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-05-15T19:59:30+00:00Added an answer on May 15, 2026 at 7:59 pm

    You’ve defined the fadeAway method for the FlashTestViewController class, not the Card class. That means that you can only call this method (or send the message depending on your preferred OOP terminology) on instances of the Card class.

    so [aCard fadeAway] is incorrect because it takes the wrong number of params, but also because aCard is a Card class instance and the fadeAway: method isn’t defined for that class (well, we don’t see the definition of it, so maybe it is but not visibly so).

    But you didn’t show the definition of the Card class so maybe you DO define the method there.

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

Sidebar

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.