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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:54:00+00:00 2026-06-10T01:54:00+00:00

I have a a class I created to generate UIButton’s I add to my

  • 0

I have a a class I created to generate UIButton’s I add to my UIView. This worked great until my conversion to ARC yesterday, not I get the following error:

-[OrderTypeButton performSelector:withObject:withObject:]: message sent to deallocated instance 0x12449f70

Here is the code to add the button to my UIView (actually a subview in my main UIView):

OrderTypeButton *btn = [[OrderTypeButton alloc]initWithOrderType:@"All Orders" withOrderCount:[NSString stringWithFormat:@"%i",[self.ordersPlacedList count]] hasOpenOrder:NO];
btn.view.tag = 6969;
btn.delegate = self;
[btn.view setFrame:CGRectMake((col * width)+ colspacer, rowHeight + (row * height),  frameWidth, frameHeight)];
[self.statsView addSubview:btn.view];

And here is my class header:

#import <UIKit/UIKit.h>

@protocol OrderTypeButtonDelegate
-(void) tapped:(id)sender withOrderType:(NSString*) orderType;
@end

@interface OrderTypeButton : UIViewController {
    id<OrderTypeButtonDelegate> __unsafe_unretained delegate;
    IBOutlet UILabel *lblOrderType;
    IBOutlet UILabel *lblOrderCount;
    NSString *orderType;
    NSString *orderCount;
    BOOL    hasOpenOrder;

}

@property (nonatomic, strong) IBOutlet UIButton *orderButton;
@property (nonatomic, strong) IBOutlet UILabel *lblOrderType;
@property (nonatomic, strong) IBOutlet UILabel *lblOrderCount;
@property (nonatomic, strong) NSString *orderType;
@property (nonatomic, strong) NSString *orderCount;
@property (nonatomic, assign) BOOL hasOpenOrder;
@property (nonatomic, unsafe_unretained) id<OrderTypeButtonDelegate> delegate;

-(id) initWithOrderType: (NSString *) anOrderType withOrderCount: (NSString *) anOrderCount hasOpenOrder: (BOOL) openOrder;
-(IBAction)btnTapped:(id)sender;

@end

Implementation:

#import "OrderTypeButton.h"

@implementation OrderTypeButton
@synthesize orderButton;
@synthesize lblOrderType, lblOrderCount, orderType, orderCount, hasOpenOrder, delegate;

-(id) initWithOrderType: (NSString *) anOrderType withOrderCount: (NSString *) anOrderCount hasOpenOrder: (BOOL) openOrder {
    if ((self = [super init])) {
        self.orderType = anOrderType;
        self.orderCount = anOrderCount;
        self.hasOpenOrder = openOrder;
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.lblOrderType.text =[NSString stringWithFormat:@"%@", self.orderType];
    self.lblOrderCount.text = [NSString stringWithFormat:@"%@", self.orderCount];
    if (self.hasOpenOrder) {
        [self.orderButton setBackgroundImage:[UIImage imageNamed:@"background-order-btn-red.png"] forState:UIControlStateNormal];
        self.lblOrderType.textColor = [UIColor whiteColor];
        self.lblOrderCount.textColor = [UIColor whiteColor];
    }
}

-(IBAction)btnTapped:(id)sender {
    NSLog(@"TAPPED");
    if ([self delegate] ) {
        [delegate tapped:sender withOrderType:self.orderType];
    }
}

- (void)viewDidUnload
{
    [self setOrderButton:nil];
    [super viewDidUnload];
}

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

@end

This seems fairly simple what I am doing here, not sure what changed with ARC that is causing me problems.

  • 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-10T01:54:02+00:00Added an answer on June 10, 2026 at 1:54 am

    Maybe ARC autorelease created button, try to store created buttons in Array

    //.h file
    @property (nonatomic, strong) NSArray *buttonsArray
    
    //.m file
    @synthesize buttonsArray
    ...
    - (void)viewDidLoad {
      buttonsArray = [NSArray array];
    ...
    OrderTypeButton *btn = [[OrderTypeButton alloc]initWithOrderType:@"All Orders"         
                                                      withOrderCount:[NSString stringWithFormat:@"%i",[self.ordersPlacedList count]]
                                                        hasOpenOrder:NO];
    btn.view.tag = 6969;
    btn.delegate = self;
    [btn.view setFrame:CGRectMake((col * width)+ colspacer, rowHeight + (row * height),  frameWidth, frameHeight)];
    [self.statsView addSubview:btn.view];
    //Add button to array
    [buttonsArray addObject:btn];
    

    Also this approach will help if you want to change buttons, or remove some specific button from view

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

Sidebar

Related Questions

I have created a UML diagram and generated a class by using Generate Code
I use MVC 3 and EF 4.3.1. I have my class created with POCO
I am following the guide at http://guides.rubyonrails.org/association_basics.html and I have created class Customer <
I have an instance of the Popen class created through subprocess.Popen. I would like
I am getting a weird behavior. I have a class that I created that
I have created a class which extends View class. public class SplashScreen extends View
I have created a class called Class1, and in another module, I want to
I have created one class as public class FormActivity extends Activity { TextView tv
I have created a class which extends Gallery. There is no onCreate() method in
I have created a class for fetching server-side data in my iOS-App, based on

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.