gpt4 book ai didi

ios - NSRange block StartRange

转载 作者:行者123 更新时间:2023-11-28 22:01:03 25 4
gpt4 key购买 nike

这里需要您的见解...

这一直在崩溃。我在某个站点上调用一个表,有人说它是导致该站点的原因,但我也可以异常(exception)。我可以在这里得到你的两分钱吗?

    NSRange blockStartRange = [pageContent rangeOfString:@"\t<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" id=\"table"];

NSRange blockEndRange = [pageContent rangeOfString:@"\t</table>" options:NSBackwardsSearch range:NSMakeRange(blockStartRange.location, [pageContent length] - blockStartRange.location)];

[HTMLString appendString:[pageContent substringWithRange:NSMakeRange(blockStartRange.location, blockEndRange.location + blockEndRange.length - blockStartRange.location)]];

// [HTMLString replaceOccurrencesOfString:@"width: 700px;" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [HTMLString length])];

}

[webView loadHTMLString:HTMLString baseURL:[NSURL URLWithString:@"http://bowlatrabs.com/"]];

错误日志

2014-08-01 15:52:22.092 Bowl at Rabs[61401:90b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSCFString rangeOfString:options:range:locale:]: Range {2147483647, 2147542871} out of bounds; string length 59222'*** First throw call stack:(0   CoreFoundation                      0x0270b1e4 __exceptionPreprocess + 1801   libobjc.A.dylib                     0x020178e5 objc_exception_throw + 442   CoreFoundation                      0x0270afbb +[NSException raise:format:] + 1393   Foundation                          0x000c38cd -[NSString rangeOfString:options:range:locale:] + 1854   Foundation                          0x000cf156 -[NSString rangeOfString:options:range:] + 695   Bowl at Rabs                        0x0002d9e8 -[LeagueController viewDidLoad] + 9206   UIKit                               0x005dc33d -[UIViewController loadViewIfRequired] + 6967   UIKit                               0x005dc5d9 -[UIViewController view] + 358   UIKit                               0x005f6942 -[UINavigationController _startCustomTransition:] + 7789   UIKit                               0x006038f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 68810  UIKit                               0x006044e9 -[UINavigationController __viewWillLayoutSubviews] + 5711  UIKit                               0x007450d1 -[UILayoutContainerView layoutSubviews] + 21312  UIKit                               0x0052c964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 35513  libobjc.A.dylib                     0x0202982b -[NSObject performSelector:withObject:] + 7014  QuartzCore                          0x04d9b45a -[CALayer layoutSublayers] + 14815  QuartzCore                          0x04d8f244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 38016  QuartzCore                          0x04d8f0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 2617  QuartzCore                          0x04cf57fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 29418  QuartzCore                          0x04cf6b85 _ZN2CA11Transaction6commitEv + 39319  QuartzCore                          0x04cf7258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 9220  CoreFoundation                      0x026d336e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 3021  CoreFoundation                      0x026d32bf __CFRunLoopDoObservers + 39922  CoreFoundation                      0x026b1254 __CFRunLoopRun + 107623  CoreFoundation                      0x026b09d3 CFRunLoopRunSpecific + 46724  CoreFoundation                      0x026b07eb CFRunLoopRunInMode + 12325  GraphicsServices                    0x035765ee GSEventRunModal + 19226  GraphicsServices                    0x0357642b GSEventRun + 10427  UIKit                               0x004bdf9b UIApplicationMain + 122528  Bowl at Rabs                        0x0000239c main + 7629  libdyld.dylib                       0x0325d725 start + 0)libc++abi.dylib: terminating with uncaught exception of type NSException(lldb) 

最佳答案

您需要处理字符串不存在的情况。 Apple 的 rangeOfString 文档: 方法说:“如果 aString 未找到或为空 (@""),则返回 {NSNotFound, 0}。”

所以你需要检查返回的范围是否有 range.location == NSNotFound 并以任何最好的方式处理它。

关于ios - NSRange block StartRange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25087770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com