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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:06:48+00:00 2026-06-15T18:06:48+00:00

I defined a block in a class: BXButton.h typedef void(^ButtonClicked)(id sender, NSDictionary *userInfo); @property

  • 0

I defined a block in a class:

BXButton.h

typedef void(^ButtonClicked)(id sender, NSDictionary *userInfo);
@property (assign, nonatomic) ButtonClicked onButtonClicked;
- (void)setClickBlock:(ButtonClicked)buttonClicked;

BXButton.m

- (void)setClickBlock:(ButtonClicked)buttonClicked {
    onButtonClicked = buttonClicked;
}
- (void)internalButtonClicked {
    DLog(@"internal clicked");
    if (self.onButtonClicked) {
        onButtonClicked(self, self.userInfo);
    }
}

And I tried to call like this in a view controller:

[_testButton setClickBlock:^(BXButton *sender, NSDictionary *userInfo) {
        DLog(@"userInfo %@", userInfo);
        [sender startLoading];
        [[BXAPIClient sharedPublicClient]postPath:@"/" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [sender endLoading];
            //[safeSelf stop];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [sender endLoading];
            [self stop];
        }];
    }];

And I always got BAD_ACCESS whenever I try to access [self method] or any variable which is defined outside of the block. Any ideas? Thanks!

  • 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-15T18:06:49+00:00Added an answer on June 15, 2026 at 6:06 pm

    The reason why you get EXC_BAD_ACCESS is because blocks are created on the stack by default, so if you reference them with an assign property they will simply cease to exist when the stack gets teared down.

    In order to fix this you should copy the block into the heap.
    One way to do that is to use copy instead of assign when defining your property.

    Change your declaration to

    @property(copy, nonatomic) ButtonClicked onButtonClicked;
    

    and use its setter/getter instead of accessing directly to the ivar when assigning a block

    - (void)setClickBlock:(ButtonClicked)buttonClicked {
        self.onButtonClicked = buttonClicked;
    }
    - (void)internalButtonClicked {
        DLog(@"internal clicked");
        if (self.onButtonClicked) {
            self.onButtonClicked(self, self.userInfo);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a block of binary data defined as: void* address, size_t binarySize; that
I'm trying Pascal, and I've defined my own class, Block . I have an
I have a protected function defined in a script block of a component defined
We know that TransactionScope class can use user-defined timeout value. But timeout exception is
Given a div such as: <div class=widget block dock clock>yada yada</div> I'd like to
I defined my User model as searchable: class User < ActiveRecord:Base searchable do #...
Running my my Test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {classpath:eq-mo-dcc-context-block.xml}) public class SpringTest { @Autowired
With the thread class defined below, if the main calls the thread by: Thread
in my class i have an array defined like this class t { var
I tried using a parameter in an emit block within a user defined action

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.