Xcode 范围或索引超出范围(应用程序正在崩溃)
我在每个视图控制器(4个视图)中都有一个带有广告横幅(内部活动)的应用程序,在我的应用程序运行2-3-4分钟后,我不断收到此错误:Xcode 范围或索引超出范围(应用程序正在崩溃),xcode,ads,banner,bounds,nscfstring,Xcode,Ads,Banner,Bounds,Nscfstring,我在每个视图控制器(4个视图)中都有一个带有广告横幅(内部活动)的应用程序,在我的应用程序运行2-3-4分钟后,我不断收到此错误: 'NSRangeException', reason: '*** -[__NSCFString substringToIndex:]: Range or index out of bounds' 我的应用程序正在崩溃&我找不到解决方案,但我确信,当我评论广告横幅代码时,我的广告横幅问题cau的某些东西一切都很好。我可以假设它发生在新请求加载到横幅上时。 这是我用于
'NSRangeException', reason: '*** -[__NSCFString substringToIndex:]: Range or index out of bounds'
我的应用程序正在崩溃&我找不到解决方案,但我确信,当我评论广告横幅代码时,我的广告横幅问题cau的某些东西一切都很好。我可以假设它发生在新请求加载到横幅上时。这是我用于广告横幅的代码: .h文件:
@property (nonatomic, retain) UIView *adBanner;
.m文件:为我需要的内容进行了合成和导入,然后:
- (void)viewWillAppear:(BOOL)animated
{
CGRect frame = CGRectMake(0, 430, 320, 50);
self.adBanner = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:self.adBanner];
// Display ad
if (![InneractiveAd DisplayAd:@"iOS_Test" withType:IaAdType_Banner withRoot:adBanner withReload:60 withParams:optionalParams])
{
adBanner.hidden = YES;
}
}
这是我的AppDelegate(不知道为什么,但可能也是这样的?)
.h文件:
#import <UIKit/UIKit.h>
@class RootViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) RootViewController *rootViewController;
@end
我真的不明白它可能是什么,以及它与NSCFString的关系:\谢谢。我不确定你是否得到了答案,但我是在没有互联网连接的情况下用这行代码得到的
NSString *value = [serverOutput substringWithRange:NSMakeRange(2, [serverOutput length] - 2 * 2)];
我必须通过检查互联网连接和if-then语句来保护它导致崩溃的是对
[NSString substringToIndex]
的调用-您发布的代码不是问题所在。继续找。
NSString *value = [serverOutput substringWithRange:NSMakeRange(2, [serverOutput length] - 2 * 2)];