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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:16:41+00:00 2026-05-30T16:16:41+00:00

Could you help me with this error. I’ve tried this code, with ARC and

  • 0

Could you help me with this error.
I’ve tried this code, with ARC and non ARC.
with ARC is OK. but with non ARC.
How could I do. help me please. ^__^;

When I push the button, the error occures.
**

#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {

    void                    (^_myOne)(void);    
    UIView*                 _viewOne;
}
@property (nonatomic, retain)   void            (^myOne)(void);
@property (nonatomic, retain)   UIView*         viewOne;
- (void)useFirstOne:(void(^)(void))blockOne;
@end
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize myOne = _myOne, viewOne = _viewOne;
- (void)useFirstOne:(void (^)(void))blockOne {

    blockOne ();
}
- (void)buttonPressed {
        [self useFirstOne:self.myOne]; //If I put this line into 'viewDidLoad', has no problem.
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    UIButton* buttonA = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buttonA.frame = CGRectMake(0, 0, 100, 44);
    buttonA.center = CGPointMake(160, 350);
    [buttonA setTitle:@"Button" forState:UIControlStateNormal];
    [buttonA addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonA];
    _viewOne = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [self.view addSubview:self.viewOne];

    _myOne = ^{
        self.viewOne.backgroundColor = [UIColor grayColor];
    };
}
@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-30T16:16:43+00:00Added an answer on May 30, 2026 at 4:16 pm

    This:

    _myOne = ^{
        self.viewOne.backgroundColor = [UIColor grayColor];
    };
    

    needs to be this:

    _myOne = Block_copy(^{
        self.viewOne.backgroundColor = [UIColor grayColor];
    });
    

    This is because block objects are stack allocated, which means that they are deallocated when they go out of scope. So when the viewDidLoad method finishes executing, the block held in _myOne will be deallocated, and if you try to use it it will crash. When you copy a block, the copy is heap allocated and will survive until it is released.

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

Sidebar

Related Questions

After doing my code update. I got this error. Could you help me figure
I have this import in my code: import com.sun.jmx.snmp.SnmpOidDatabaseSupport; but i get following error:
Hi Guys could you please help me refactor this so that it is sensibly
Could someone please help explain why I can't get this to work? I properly
I've recently written this with help from SO. Now could someone please tell me
This is probably a kinda commonly asked question but I could do with help
Hi could you help me with this error? Cannot access a disposed object. Object
I wonder if any of you could help with this problem. The following code
I hope someone could help me on this. I want to add a month
OK, if anyone could help me with this I'd be much appreciative. If you

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.