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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:15:08+00:00 2026-05-22T23:15:08+00:00

I have created a subclass of UIControl called ToggleImageControl via the following code (with

  • 0

I have created a subclass of UIControl called ToggleImageControl via the following code (with reference to the following post Checkbox image toggle in UITableViewCell)

@interface ToggleImageControl : UIControl 
{
    BOOL photoIsStarred;
    UIImageView *imageView;
    UIImage *normalImage;
    UIImage *selectedImage;
}

@property (nonatomic, assign) BOOL photoIsStarred;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIImage *normalImage;
@property (nonatomic, retain) UIImage *selectedImage;

- (void) toggleImage;
@end


@implementation ToggleImageControl

@synthesize photoIsStarred, imageView, normalImage,selectedImage;

- (id)initWithFrame:(CGRect)frame 
{
    NSLog(@"in inti with frame method");
    self.normalImage = [UIImage imageNamed: @"blank_star.png"];
    self.selectedImage = [UIImage imageNamed: @"star.png"];
    self.imageView = [[UIImageView alloc] initWithImage: normalImage];

    // set imageView frame
    [self addSubview: imageView];

    [self addTarget: self action: @selector(toggleImage) forControlEvents: UIControlEventTouchDown];

return self;
}

- (void) toggleImage
{
    NSLog(@"image toggled");
    self.photoIsStarred = !photoIsStarred;
    self.imageView.image = (photoIsStarred ? selectedImage : normalImage); 
}

@end

I tried to create an instance of ToggleImageControl in a table cell but was not able to display the ‘normal image’. Is there something missing from my implementation below?

//In a UItableview cell
ToggleImageControl *toggleControl = [[ToggleImageControl alloc]initWithFrame:CGRectMake(670, 10,80, 80)];

[cell.contentView addSubview:toggleControl];
  • 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-22T23:15:09+00:00Added an answer on May 22, 2026 at 11:15 pm

    Make sure to call [super initWithFrame:frame] in your initWithFrame: method.

    e.x.

    self = [super initWithFrame:frame];
    if (self) {
    
      // Initialization
    
    }
    
    return self;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a a subclass of Table in my ASP.NET project which creates.
(iPhone SDK 3.x:) I have a UIControl subclass that creates a different number of
I have created a subclass of UIImageView and I am handling the touches for
I have created a subclass of UIImageView and I am handling the touches for
I have created a subclass of a generic list so that I could implement
I have created a Class (subclass of NSObject) which will hold all my SQLs/dbConnections
I have created a subclass for a UIButton and was hoping to pass a
I have an issue similar to the following post: Silverlight DataGridTextColumn Binding Visibility I
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up

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.