0

I have an exception like this:

Thread 1: EXC_Breakpoint (code = EXC_I386_BPT,subcode=0x0)

In my story board i have 3 controllers. Navigation controller, UIViewController and then a tableviewcontroller. When the app first launches UIViewController is shown. I add some stuff to the Core Data DB. Then on this controller itself i have a "Check Records" bar button. I click that and move to the 3rd controller the tableviewcontroller. Here i can see the records that i added on that day. I click the one i just added and traverse back to the UIviewcontroller screen using NSNotifications like this:

//This code is in tableviewcontroller.didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ITMAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    appDelegate.salesOrderObject = [self.salesOrdersArray objectAtIndex:indexPath.row];

    NSNotification *notification =[NSNotification notificationWithName:@"reloadRequest"
                                                                object:self];
    [[NSNotificationCenter defaultCenter] postNotification : notification];

    [self.navigationController popViewControllerAnimated:YES];
}

In my ViewController viewDidLoad i write this code to listen to the notification.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(newReloadData)
                                             name:@"reloadRequest"
                                           object:nil];


-(void)newReloadData
{
self.salesOrder =  self.appDelegate.salesOrderObject; //self.reloadedSOObject; //appDelegate.salesOrderObject;

if(self.salesOrder !=nil)
{
//I add UItextviews,textfields,buttons etc here to a scrollview.
ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:CGRectMake(187, 660, 400, 400)
                                                     andOrderedItem:@"New"
                                                             andTag:self.tagNumber
                                                      withFoldArray:self.foldTypeArray
                                                      withRollArray:self.rollTypeArray];

        cView.tag =self.tagNumber;
        NSLog(@"Assigned tag is %d",cView.tag);

        cView.delegate = self;

        //[self.scrollView addSubview:customView];

        //self.scrollView.contentSize = CGRectMake(187, 660, 400, 400).size;


        CGPoint scrollPoint = CGPointMake(0.0, (cView.frame.origin.y/500)*400);
        [self.scrollView setContentOffset:scrollPoint animated:YES];

        [self.scrollView addSubview:cView];

        CGFloat scrollViewHeight = 0.0f;
        for (UIView *view in self.scrollView.subviews)
        {
            scrollViewHeight += view.frame.size.height;
        }

        CGSize newSize = CGSizeMake(320,scrollViewHeight);
        //CGRect newFrame = (CGRect){CGPointZero,newSize};
        [self.scrollView setContentSize:newSize];
        NSLog(@"750 the tag number is %d",self.tagNumber);
        NSLog(@"the scroll view height is %f",scrollViewHeight);
        self.currentCGRectLocation = cView.frame;
}
}

I am thinking if the exception occurs at adding something to scroll view.Or on looking some more on stack overflow it could be either because of delegate or NSnotification. I cant figure out why and where the exception occurs.Does writing this line of code give me this exception?

[self.navigationController popViewControllerAnimated:YES];

this question is extension of this question Adding Customview to UIScrollview results in stuck screen when Scrolling

I have no idea where/how its getting this exception. If you need more info please ask. Thanks...

Community
  • 1
  • 1
RookieAppler
  • 1,517
  • 5
  • 22
  • 58
  • maybe you need try to enable zombies and guard malloc maybe you can get some detail on error . or use some breakpoints to understand after what point it occurs and I would use `popViewControllerAnimated:NO` – SpaceDust__ Dec 26 '12 at 18:23
  • @SpaceDust. Thanks. I enabled zombies and guard malloc, but no use.I also changed the popViewControllerAnimated to NO and it didn't work. So the exception seems to be occurring at [self.navigationController popViewControllerAnimated:NO]; line.It hits this line and then it throws the above exception. Also can i pass object to AppDelegate class like that?I am storing my object in appDelegate class at didSelectRowAtIndexPath and while working with the notification i retrieve an object from the AppDelegate class. – RookieAppler Dec 26 '12 at 18:46
  • one thing might be you first call `newReloadData` because you notify notification center that what class has `newReloadData` method should run it, so you need to first pop the view then call the notification, just try change the line order first call `[self.navigationController popViewControllerAnimated:YES];` then call `[[NSNotificationCenter defaultCenter] postNotification : notification];` – SpaceDust__ Dec 26 '12 at 19:07
  • I am glad that worked, I am looking at your code but honestly I have no idea why scroll is disabled, maybe you should ask another question or wait for someone to solve your issue. But about `NSNotifications` part I deserve my answer is checked :) – SpaceDust__ Dec 26 '12 at 19:19

1 Answers1

1

One thing might be when you call newReloadData you notify notification center that what class has@"reloadRequest" string with newReloadData method should run it, so you need to first pop the view then call the notification

Just try change the line order first call [self.navigationController popViewControllerAnimated:YES]; then call [[NSNotificationCenter defaultCenter] postNotification : notification];

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ITMAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    appDelegate.salesOrderObject = [self.salesOrdersArray objectAtIndex:indexPath.row];

    NSNotification *notification =[NSNotification notificationWithName:@"reloadRequest"
                                                                object:self];
    //here first pop view
    [self.navigationController popViewControllerAnimated:YES];

    //then send notification before scopes end
    [[NSNotificationCenter defaultCenter] postNotification : notification];


}
SpaceDust__
  • 4,844
  • 4
  • 43
  • 82
  • @SpaceDust.Thanks.That Worked.NO exception!!!. I can see the viewcontroller fine, but the scroll is disenabled. Screen is stuck.I can neither move up/down – RookieAppler Dec 26 '12 at 19:21