0

我有一个这样的例外:

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

在我的故事板中,我有 3 个控制器。导航控制器、UIViewController 和 tableviewcontroller。当应用程序首次启动时,会显示 UIViewController。我在 Core Data DB 中添加了一些东西。然后在这个控制器本身上我有一个“检查记录”栏按钮。我单击它并移动到第三个控制器 tableviewcontroller。在这里我可以看到我那天添加的记录。我单击刚刚添加的那个,然后使用 NSNotifications 回到 UIviewcontroller 屏幕,如下所示:

//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];
}

在我的 ViewController viewDidLoad 中,我编写了这段代码来收听通知。

[[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;
}
}

我在想如果在向滚动视图中添加一些东西时发生异常。或者在堆栈溢出时查看更多可能是因为委托或 NSnotification。我无法弄清楚异常发生的原因和位置。编写这行代码是否会给我这个异常?

[self.navigationController popViewControllerAnimated:YES];

这个问题是这个问题的扩展 将Customview添加到UIScrollview会导致滚动时卡屏

我不知道它在哪里/如何得到这个异常。如果您需要更多信息,请询问。谢谢...

4

1 回答 1

1

一件事可能是当你打电话newReloadData 通知通知中心时,哪个类有@"reloadRequest"字符串 newReloadData方法应该运行它,所以你需要先弹出视图然后调用通知

只需尝试更改线路顺序先调用[self.navigationController popViewControllerAnimated:YES];然后调用[[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];


}
于 2012-12-26T19:17:40.473 回答