【发布时间】:2012-12-26 18:14:03
【问题描述】:
我有一个这样的例外:
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];
这个问题是这个问题的延伸 Adding Customview to UIScrollview results in stuck screen when Scrolling
我不知道它在哪里/如何得到这个异常。如果您需要更多信息,请询问。谢谢...
【问题讨论】:
-
也许你需要尝试启用僵尸和保护 malloc 也许你可以得到一些关于错误的细节。或者使用一些断点来了解它发生在什么点之后,我会使用
popViewControllerAnimated:NO -
@SpaceDust。谢谢。我启用了僵尸和守卫 malloc,但没有用。我还将 popViewControllerAnimated 更改为 NO,但它没有工作。所以异常似乎发生在 [self.navigationController popViewControllerAnimated:NO]; line.It 命中这一行,然后抛出上述异常。我也可以像这样将对象传递给 AppDelegate 类吗?我将我的对象存储在 didSelectRowAtIndexPath 的 appDelegate 类中,并且在处理通知时我从 AppDelegate 类中检索一个对象。
-
一件事可能是你先调用
newReloadData,因为你通知通知中心哪个类有newReloadData方法应该运行它,所以你需要先弹出视图然后调用通知,试试更改线路顺序首先调用[self.navigationController popViewControllerAnimated:YES];然后调用[[NSNotificationCenter defaultCenter] postNotification : notification]; -
我很高兴这有效,我正在查看您的代码,但老实说我不知道为什么滚动被禁用,也许您应该问另一个问题或等待有人解决您的问题。但是关于
NSNotifications部分我值得我的答案被检查:)
标签: ios exception uiscrollview delegates uinavigationcontroller