开发者

NSObjectInaccessibleException after opening a uiviewcontroller

开发者 https://www.devze.com 2023-03-22 21:26 出处:网络
I am developing a app where with a custom tabbar opening different tableview. The information to the tableview is feeded by a JSON remote feed. And saved into Core Data with custom nsmanagedobject.

I am developing a app where with a custom tabbar opening different tableview. The information to the tableview is feeded by a JSON remote feed. And saved into Core Data with custom nsmanagedobject.

The error is triggered after I opening and closing uiview in didSelectRowAtIndexPath. The detail view is opening over the tableview and have a closing button in the corner. The view is only for read articles, not for edit, rewrite or delete. The error appear after I have opened and closed the detail view twice.

The log say that the NSManagedObject is has been invalidated. But how, when i am not deleting or updating the object. It happening with every cell row.

What i am doing wrong?

The log:

* Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'The NSManagedObject with ID:0x75401c0 has been invalidated.'

* Call stack at first throw:

(

0 CoreFoundation 0x013d15a9 exceptionPreprocess + 185

1 libobjc.A.dylib 0x01525313 objc_exception_throw + 44

2 CoreData 0x0117f120 -[NSFaultHandler _fireFirstAndSecondLevelFaultsForObject:withContext:] + 0

3 CoreData 0x01110933 _PF_FulfillDeferredFault + 499

4 CoreData 0x011149af _sharedIMPL_pvfk开发者_运维问答_core + 95

5 CoreData 0x011247c0 _pvfk_9 + 32

6 Ultima 0x00014bf7 -[ProgramTable tableView:cellForRowAtIndexPath:] + 4247

7 UIKit 0x004c1b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634

8 UIKit 0x004b74cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75

9 UIKit 0x004cc8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561

10 UIKit 0x004c490c -[UITableView layoutSubviews] + 242

11 QuartzCore 0x0014fa5a -[CALayer layoutSublayers] + 181

12 QuartzCore 0x00151ddc CALayerLayoutIfNeeded + 220

13 QuartzCore 0x000f70b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310

14 QuartzCore 0x000f8294 _ZN2CA11Transaction6commitEv + 292

15 QuartzCore 0x000f846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99

16 CoreFoundation 0x013b289b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27

17 CoreFoundation 0x013476e7 __CFRunLoopDoObservers + 295

18 CoreFoundation 0x013101d7 __CFRunLoopRun + 1575

19 CoreFoundation 0x0130f840 CFRunLoopRunSpecific + 208

20 CoreFoundation 0x0130f761 CFRunLoopRunInMode + 97

21 GraphicsServices 0x01e6d1c4 GSEventRunModal + 217

22 GraphicsServices 0x01e6d289 GSEventRun + 115

23 UIKit 0x0045ac93 UIApplicationMain + 1160

24 Ultima 0x000028e9 main + 121

25 Ultima 0x00002865 start + 53 )

terminate called throwing an exception[Switching to process 429 thread 0xec03]

sharedlibrary apply-load-rules all

Current language: auto; currently objective-c

My cellForRowAtIndexPath looks like:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

ProgramCelle *cell = (ProgramCelle*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[ProgramCelle alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
int row = indexPath.row;
int section = indexPath.section;

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"HH:mm"];

if(section == 0){
    Program *p =[eight objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;

}
if(section == 1){
    Program *p =[nine objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 2){
    Program *p =[ten objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 3){
    Program *p =[eleven objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 4){
    Program *p =[twelve objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 5){
    Program *p =[thirteen objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 6){
    Program *p =[fourteen objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 7){
    Program *p =[fifthteen objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 8){

    Program *p =[sixteen objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
if(section == 9){
    Program *p =[seventeen objectAtIndex:row];
    cell.primaryTitle.text = p.title;
    cell.primaryTitle.textColor = [UIColor blueColor];
    Scene *s = p.scene;
    cell.secondaryTitle.text = s.name;
    NSDate *dato = p.tidspunkt;

    NSString *time = [formatter stringFromDate:dato];
    cell.klokke.text = time;
}
[formatter release];
return cell;
}

Where eight, nine, ten ... are NSArrays that is initiated in viewdidLoad and released in dealloc.


You probably are not retaining the objects long enough (aka autorelease). So when some time passes, you try to access something that there is not there anymore. Try passing your data to an NSMutableArray and use it as your datasource on your "tableView:cellForRowAtIndexPath".


The NSObjectInaccessibleException in Core Data means that you've got a reference to an object that is not in the persistent store.

Usually, this means that you've deleted it from the context while maintaining a reference to it elsewhere e.g. an object property or an array.

However, you can also get the error if you don't properly add an object to a store in the first place. This happens when you create a NSManagedObject instance without properly inserting it in a valid context.

In any, case, your immediate problem is actually in the code where you create and/or save these managed objects and not in the tableview controller code. That is simply where the error occurs because that is where you try to access the invalid managed objects.


I found it out by my self. When I am closing the overlaying viewcontroller, I have to reload the data of the tableview. It was not a problem of any array or deleting any object. Like

[myTable reloadData];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号