कभी-कभी (शायद ही कभी होता है) मुझे Object has been deleted or invalidated.
त्रुटि मिली, जब मेरी मॉडल ऑब्जेक्ट को किसी संपत्ति या एफ़नेटवर्किंग ब्लॉक के अंदर संशोधित करने का प्रयास किया गया। क्या कोई मुझे यह जानने में मदद कर सकता है कि मैं क्या गलत कर रहा हूं?त्रुटि: ऑब्जेक्ट हटा दिया गया है या अमान्य कर दिया गया है। (दायरे)
त्रुटि - केस 1:
कोड:
- (void)myFunction {
Model *model = [Model objectForPrimaryKey:1];
if (model) {
[self updateModel:model];
}
}
- (void)updateModel:(Model *)model {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager PUT:@"http://www.example.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
[[RLMRealm defaultRealm] beginWriteTransaction];
model.updated = YES; // Crash: Object has been deleted or invalidated.
[[RLMRealm defaultRealm] commitWriteTransaction];
} failure:nil];
}
त्रुटि - केस 2:
संपत्ति:
@property (strong, nonatomic) Model *model;
कोड:
- (void)myFunction {
Model *model = [Model objectForPrimaryKey:1];
if (model) {
self.model = model;
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Would you like to edit the model?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[alert show];
}
}
UIAlertView प्रतिनिधि:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[RLMRealm defaultRealm] beginWriteTransaction];
self.model.updated = YES; // Crash: Object has been deleted or invalidated.
[[RLMRealm defaultRealm] commitWriteTransaction];
}
}
धन्यवाद।
मॉडल भेजने के बजाय मैं मॉडल प्राथमिक कुंजी भेजने के लिए बदल गया, और हर बार जब आवश्यक हो तो मैं इसे पहले खोजने की कोशिश करता हूं। क्रैश चला गया है और यह ठीक से काम कर रहा है, धन्यवाद! –