In the past, the same method was used for block calls, but this time it was a crash. Mindless crash. Once called, it was a crash. The console did not print any crash information. Then it asked Du Niang about the wild pointer. To be honest, I read the code line by line. I searched for it for several hours. Later, I found that a new instance was created when the navigation controller was pushed, This causes the system to release the old instance
first said the functions I want to achieve: jump from the root controller to the first controller, then call the block in the first controller to change the background color of the controller and return to the first controller. p>
Code in the first controller:
//The second controller to jump to
@property (nonatomic, strong) BSOneController *oneVC;
– (void)viewDidLoad {
[super viewDidLoad];
BSOneController *oneVC = [[BSOneController alloc] init];
self.oneVC = oneVC;
oneVC.changeColor = ^(UIColor *color) {
self.view.backgroundColor = color;
[self.navigationController popViewControllerA nimated:YES ];
};
}
– (void)goOneVC:(UIButton *)btn{
//cause of crash: a new instance is created here, resulting in the release of self.onevc in advance, and then calling the instance’s block to cause crash
// BSOneController *one = [[BSOneController alloc] init];
// [self.navigationController pushViewC ontroller:one animated :YES];
[self.navigationController pushViewC ontroller:self.oneVC animated :YES];
}
Similar Posts:
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- Expected rbrace error encountered in DW
- [Solved] error: resource style/AppTheme (aka com.example.myapplication:style/AppTheme
- Vue: How to use Vue-router in Axios
- This application has no explicit mapping for /error, so you are seeing this as a fallback
- Rabbitmq startup error kernel PID terminated [How to Solve]
- Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Setting and Research on splash of unity startup interface (logo is too large and background is fuzzy)
- [Solved] IllegalArgumentException: object is not an instance of declaring class