Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView\u ContentOffsetForCrollingToRowatineXPath:atScrollPosition:如何解决此问题?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableView\u ContentOffsetForCrollingToRowatineXPath:atScrollPosition:如何解决此问题?

Ios UITableView\u ContentOffsetForCrollingToRowatineXPath:atScrollPosition:如何解决此问题?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有三个视图控制器,在第三个视图中,我有一个按钮,它将被重定向到父视图(第一个视图控制器),这是一个表视图。所以当我点击按钮时,我就崩溃了 - (IBAction)createThread:(id)sender { [[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil]; } 我在堆栈溢出中找到了解决方案,但这并没有

我有三个视图控制器,在第三个视图中,我有一个按钮,它将被重定向到父视图(第一个视图控制器),这是一个表视图。所以当我点击按钮时,我就崩溃了

- (IBAction)createThread:(id)sender {
       [[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
 }
我在堆栈溢出中找到了解决方案,但这并没有帮助

请告诉我一个解决办法

崩溃日志:

      Terminating app due to uncaught exception 'NSRangeException', reason: '-    [UITableView  

  contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond   bounds (0) for section (0).'
  *** First throw call stack:
 (
0   CoreFoundation                      0x000000010efeff35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010ec88bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010efefe6d +[NSException raise:format:] + 205
3   UIKit                               0x000000010d616d7c -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 1178
4   UIKit                               0x000000010d61794a -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 33
5   Inxed                               0x000000010b798fd4 -[IXDetailedMessageViewController openCommentView:] + 7396
6   Inxed                               0x000000010b794835 -[IXDetailedMessageViewController viewDidAppear:] + 149
7   UIKit                               0x000000010d65a871 -[UIViewController _setViewAppearState:isAnimating:] + 567
8   UIKit                               0x000000010d65b03b -[UIViewController _endAppearanceTransition:] + 304
9   UIKit                               0x000000010d632dd9 -[UIPresentationController transitionDidFinish:] + 699
10  UIKit                               0x000000010dbf8298 -[_UIFullscreenPresentationController transitionDidFinish:] + 71
11  UIKit                               0x000000010d635301 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 133
12  UIKit                               0x000000010dc87ac3 -[_UIViewControllerTransitionContext completeTransition:] + 110
13  UIKit                               0x000000010dca1d89 -[UIViewControllerBuiltinTransitionViewAnimator animateTransition:] + 2694
14  UIKit                               0x000000010d6351d3 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 1842
15  UIKit                               0x000000010d661ab0 +[UIViewController _scheduleTransition:] + 103
16  UIKit                               0x000000010d634a92 -[UIPresentationController runTransitionForCurrentState] + 1243
17  UIKit                               0x000000010d5a25ce +[UIView(Animation) performWithoutAnimation:] + 65
18  UIKit                               0x000000010d6663c4 -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:] + 685
19  UIKit                               0x000000010d5a25ce +[UIView(Animation) performWithoutAnimation:] + 65
20  UIKit                               0x000000010d666036 -[UIViewController _dismissViewControllerWithTransition:from:completion:] + 880
21  UIKit                               0x000000010d661a18 +[UIViewController _performWithoutDeferringTransitions:] + 101
22  UIKit                               0x000000010d66573f -[UIViewController dismissViewControllerWithTransition:completion:] + 627
23  UIKit                               0x000000010d667814 -[UIViewController dismissViewControllerAnimated:completion:] + 255
24  Inxed                               0x000000010b924ad5 -[IXConfirmFeedbackPage createThread:] + 1093
25  UIKit                               0x000000010d5328be -[UIApplication sendAction:to:from:forEvent:] + 75
26  UIKit                               0x000000010d639410 -[UIControl _sendActionsForEvents:withEvent:] + 467
27  UIKit                               0x000000010d6387df -[UIControl touchesEnded:withEvent:] + 522
28  UIKit                               0x000000010d578308 -[UIWindow _sendTouchesForEvent:] + 735
29  UIKit                               0x000000010d578c33 -[UIWindow sendEvent:] + 683
30  UIKit                               0x000000010d5459b1 -[UIApplication sendEvent:] + 246
31  UIKit                               0x000000010d552a7d _UIApplicationHandleEventFromQueueEvent + 17370
32  UIKit                               0x000000010d52e103 _UIApplicationHandleEventQueue + 1961
33  CoreFoundation                      0x000000010ef25551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
34  CoreFoundation                      0x000000010ef1b41d __CFRunLoopDoSources0 + 269
35  CoreFoundation                      0x000000010ef1aa54 __CFRunLoopRun + 868
36  CoreFoundation                      0x000000010ef1a486 CFRunLoopRunSpecific + 470
37  GraphicsServices                    0x00000001103899f0 GSEventRunModal + 161
38  UIKit                               0x000000010d531420 UIApplicationMain + 1282
39  Inxed                               0x000000010b8d2703 main + 115
40  libdyld.dylib                       0x000000010fa86145 start + 1
41  ???                                 0x0000000000000001 0x0 + 1
  )
  libc++abi.dylib: terminating with uncaught exception of type NSException
Opencommentview:

 - (IBAction)openCommentView:(id)sender
{

 NSString *ver = [[UIDevice currentDevice] systemVersion];
float ver_float = [ver floatValue];
ThreadInfo *info=[self selectedThreadInfo];
if(info!=nil)
{
    if([info.isThreadBlocked boolValue] || [info.isThreadRemoved boolValue] ||  [info.isThreadEnded boolValue])
    {
        self.tapButton.alpha=0.5;

        UIAlertView *errorAlert=[[UIAlertView alloc]initWithTitle:@"This thread has been closed" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
    }
    else
    {

        self.view.backgroundColor=[UIColor whiteColor];
        self.commentTextView.hidden=NO;
        self.commentTextView.text=@"";
        self.commentTextCountLabel.text=@"";
        float commentViewY=0.0,tableViewHeight=0.0,countLabelY=0.0;
        if(IS_IPHONE5)
        {
            if(ver_float>=8.0)
            {
                commentViewY=200.0;
                tableViewHeight=180.0;
                countLabelY=90;
                self.commentTextView.frame=CGRectMake(self.commentTextView.frame.origin.x, self.commentTextView.frame.origin.y, self.commentTextView.frame.size.width, 112);
            }
            else
            {
                commentViewY=240.0;
                tableViewHeight=220.0;
                countLabelY=90;
                self.commentTextView.frame=CGRectMake(self.commentTextView.frame.origin.x, self.commentTextView.frame.origin.y, self.commentTextView.frame.size.width, 108);
            }




        }
        else
        {
            if(ver_float>=8.0)
            {
                countLabelY=56;

                commentViewY=150;
                tableViewHeight=130;
                self.commentTextView.frame=CGRectMake(self.commentTextView.frame.origin.x, self.commentTextView.frame.origin.y, self.commentTextView.frame.size.width, 75);

            }
            else
            {
                countLabelY=76;
                commentViewY=170;
                tableViewHeight=150;
                self.commentTextView.frame=CGRectMake(self.commentTextView.frame.origin.x, self.commentTextView.frame.origin.y, self.commentTextView.frame.size.width, 90);
            }
        }
        id  sectionInfo =
        [[_fetchedResultsController sections] objectAtIndex:0];

        NSInteger count = [sectionInfo numberOfObjects];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:count-1 inSection:1];

        [self.commentTextView becomeFirstResponder];
        self.commentTextCountLabel.frame=CGRectMake(self.commentTextCountLabel.frame.origin.x, countLabelY, self.commentTextCountLabel.frame.size.width, self.commentTextCountLabel.frame.size.height);

        self.isCommentsOpen=YES;
        self.tapButton.hidden=YES;
        self.postButton.hidden=NO;
        self.postButton.enabled=NO;
        if(self.isFromComments)
        {
            self.commentView.frame=CGRectMake(self.commentView.frame.origin.x, commentViewY, self.commentView.frame.size.width, self.commentView.frame.size.height);
            self._mDetailedMessageTableView.frame=CGRectMake(self._mDetailedMessageTableView.frame.origin.x,0, self._mDetailedMessageTableView.frame.size.width, tableViewHeight);
            // self.commentTextView.clipsToBounds = NO;
            id  sectionInfo =
            [[_fetchedResultsController sections] objectAtIndex:0];

            if([sectionInfo numberOfObjects]!=0)
            {
                [self._mDetailedMessageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

            }
            else
            {
                [self._mDetailedMessageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
            }

        }
        else
        {
            [UIView animateWithDuration:0.2
                             animations:^{

                                 self.commentView.frame=CGRectMake(self.commentView.frame.origin.x, commentViewY, self.commentView.frame.size.width, self.commentView.frame.size.height);
                                 self._mDetailedMessageTableView.frame=CGRectMake(self._mDetailedMessageTableView.frame.origin.x,0, self._mDetailedMessageTableView.frame.size.width, tableViewHeight);


                                 self.commentTextView.clipsToBounds = NO;
                                 id  sectionInfo =
                                 [[_fetchedResultsController sections] objectAtIndex:0];

                                 if([sectionInfo numberOfObjects]!=0)
                                 {
                                     [self._mDetailedMessageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

                                 }
                                 else
                                 {
                                     [self._mDetailedMessageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                                 }

                             }
                             completion:^(BOOL finished){

                             }];
        }
    }
}
}

[tableview重新加载数据]

我认为下面代码中的
else
部分正在制造问题

if([sectionInfo numberOfObjects]!=0)
{
   [self._mDetailedMessageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

}
else
{
  [self._mDetailedMessageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}

假设
numberOfObjects==0
将进入else案例。在这里,您告诉tableView滚动到第0节中的InExpathForRow:0。零是一个完全有效的行,它是tableView的第一行。实际上,此时您的
numberOfObjects
为零,这意味着tableView中没有行。这会导致撞车。因此,请删除不需要的
else
案例。

您是以编程方式滚动还是设置内容偏移量?以编程方式滚动我可以看到
openCommentView
方法
ixtailedMessageViewController
?。我认为有一个问题suspect@Jan:你解决了吗?你的行数呢??它是硬编码的还是取决于服务器数据?取决于服务器数据然后在行计数位置放置一个断点,并检查它是否为空,所以我需要删除else条件?当然。如果你没有任何争吵。你为什么要这么做呢?不,它仍然在崩溃。因为同样的原因崩溃?
if([sectionInfo numberOfObjects]!=0)
{
   [self._mDetailedMessageTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

}
else
{
  [self._mDetailedMessageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}