gpt4 book ai didi

objective-c - 当我加载包含 webview 的 View Controller 时,iPhone 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 04:39:42 25 4
gpt4 key购买 nike

我有一个 NavigationController -> UIViewController -> UIWebView

我有一个从 tableViewController 到 NavigationController 的模态转场。

每当我执行此操作时,应用程序就会崩溃。我没有在 Controller 中编写任何代码,只是简单地将 uiwebview 放在 Storyboard中。如果我删除 uiwebview,segue 运行得很好。

调试器在我的单例对象“CoData.m”中的单例创建行处停止。当我打印它的描述时,它会打印 uiwebview 描述,但它是 NSObject 类型的自定义类。

看这里http://cl.ly/GZWJ screenshot
在这里 http://cl.ly/Gaig screenshot发生了什么事?

这就是它崩溃的地方。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"webView" sender:self];
}

编辑**CoData.m 的删节内容

import "CoData.h"

@implementation CoData

CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(CoData);

@synthesize photoSessions = _photoSessions;
@synthesize userPhotos = _userPhotos;
@synthesize photoSet = _photoSet;
@synthesize user = _user;
@synthesize pushEnabled = _pushEnabled;
@synthesize showToast = _showToast;
@synthesize highQualityPhotos = _highQualityPhotos;
@synthesize photoQualityChanged = _photoQualityChanged;
@synthesize isRetina = _isRetina;
@synthesize campers = _campers;
@synthesize camperNames = _camperNames;
@synthesize infoStream = _infoStream;

-(NSCache *)photoSet
{
if(!_photoSet){
_photoSet = [[NSCache alloc] init];
}
return _photoSet;
}

-(NSDictionary *)user
{
if(!_user){
_user = [[NSDictionary alloc] init];
}
return _user;
}

-(BOOL)isRetina
{
if(!_isRetina){
_isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2);
}
return _isRetina;
}

-(void)loadDataFromPlist
{


}

-(void)loginAPIUser
{

}

-(void)saveDataToPlist
{



}

@end

以及 CWL_SYNTHESIZE_SINGLETON_FOR_CLASS 宏

//
// CWLSynthesizeSingleton.h
// CocoaWithLove
//
// Created by Matt Gallagher on 2011/08/23.
// Copyright (c) 2011 Matt Gallagher. All rights reserved.
//
// Permission is given to use this source code file, free of charge, in any
// project, commercial or otherwise, entirely at your risk, with the condition
// that any redistribution (in part or whole) of source code must retain
// this copyright and permission notice. Attribution in compiled projects is
// appreciated but not required.
//

#import <objc/runtime.h>

#define CWL_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR(classname, accessorMethodName) \
+ (classname *)accessorMethodName;

#if __has_feature(objc_arc)
#define CWL_SYNTHESIZE_SINGLETON_RETAIN_METHODS
#else
#define CWL_SYNTHESIZE_SINGLETON_RETAIN_METHODS \
- (id)retain \
{ \
return self; \
} \
\
- (NSUInteger)retainCount \
{ \
return NSUIntegerMax; \
} \
\
- (oneway void)release \
{ \
} \
\
- (id)autorelease \
{ \
return self; \
}
#endif

#define CWL_SYNTHESIZE_SINGLETON_FOR_CLASS_WITH_ACCESSOR(classname, accessorMethodName) \
\
static classname *accessorMethodName##Instance = nil; \
\
+ (classname *)accessorMethodName \
{ \
@synchronized(self) \
{ \
if (accessorMethodName##Instance == nil) \
{ \
accessorMethodName##Instance = [super allocWithZone:NULL]; \
accessorMethodName##Instance = [accessorMethodName##Instance init]; \
method_exchangeImplementations(\
class_getClassMethod([accessorMethodName##Instance class], @selector(accessorMethodName)),\
class_getClassMethod([accessorMethodName##Instance class], @selector(cwl_lockless_##accessorMethodName)));\
method_exchangeImplementations(\
class_getInstanceMethod([accessorMethodName##Instance class], @selector(init)),\
class_getInstanceMethod([accessorMethodName##Instance class], @selector(cwl_onlyInitOnce)));\
} \
} \
\
return accessorMethodName##Instance; \
} \
\
+ (classname *)cwl_lockless_##accessorMethodName \
{ \
return accessorMethodName##Instance; \
} \
\
+ (id)allocWithZone:(NSZone *)zone \
{ \
return [self accessorMethodName]; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return self; \
} \
- (id)cwl_onlyInitOnce \
{ \
return self;\
} \
\
CWL_SYNTHESIZE_SINGLETON_RETAIN_METHODS

#define CWL_DECLARE_SINGLETON_FOR_CLASS(classname) CWL_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR(classname, shared##classname)
#define CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(classname) CWL_SYNTHESIZE_SINGLETON_FOR_CLASS_WITH_ACCESSOR(classname, shared##classname)

最佳答案

我查看了 http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html 中的代码。好吧..你不能像这样创建单例的任何原因:

+(MyClass *)singleton {
static dispatch_once_t pred;
static MyClass *shared = nil;

dispatch_once(&pred, ^{
shared = [[MyClass alloc] init];
});
return shared;
}

( src )

关于objective-c - 当我加载包含 webview 的 View Controller 时,iPhone 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10567500/

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