我有一个这样的异常(exception):
Thread 1: EXC_Breakpoint (code = EXC_I386_BPT,subcode=0x0)
在我的 Storyboard中,我有 3 个 Controller 。导航 Controller 、UIViewController 和 tableviewcontroller。当应用程序首次启动时,会显示 UIViewController。我向核心数据数据库添加了一些内容。然后在这个 Controller 本身上我有一个“检查记录”栏按钮。我单击它并移动到第三个 Controller ,即 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;
}
}
我在想,如果异常发生在向 ScrollView 添加某些内容时。或者在查看更多堆栈溢出时,可能是因为委托(delegate)或 NSnotification。我无法弄清楚异常发生的原因和位置。编写这行代码是否会出现此异常?
[self.navigationController popViewControllerAnimated:YES];
这个问题是这个问题的延伸 Adding Customview to UIScrollview results in stuck screen when Scrolling
我不知道它在哪里/如何得到这个异常。如果您需要更多信息,请询问。谢谢...
最佳答案
一件事可能是,当您调用 newReloadData
时,您通知通知中心应该运行哪个类具有 @"reloadRequest"
字符串和 newReloadData
方法它,所以你需要先弹出 View 然后调用通知
只需尝试更改行顺序,首先调用 [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];
}
关于ios - 使用 NSNotifications 从 TableViewController 导航回 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14044441/