Objective c 当我加载包含webview的viewcontroller时,iphone应用程序崩溃
我有一个NavigationController->UIViewController->UIWebView 我有一个从tableViewController到NavigationController的模式序列 每当我执行此步骤时,应用程序就会崩溃。我没有在控制器中编写代码,只是在情节提要中放置了一个uiwebview。如果删除uiwebview,segue运行正常 调试器在我的单例对象“CoData.m”中的单例创建行停止。当我打印它的描述时,它会打印uiwebview描述,但它是NSObject类型的自定义类 看这里Objective c 当我加载包含webview的viewcontroller时,iphone应用程序崩溃,objective-c,ios,uiwebview,singleton,exc-bad-access,Objective C,Ios,Uiwebview,Singleton,Exc Bad Access,我有一个NavigationController->UIViewController->UIWebView 我有一个从tableViewController到NavigationController的模式序列 每当我执行此步骤时,应用程序就会崩溃。我没有在控制器中编写代码,只是在情节提要中放置了一个uiwebview。如果删除uiwebview,segue运行正常 调试器在我的单例对象“CoData.m”中的单例创建行停止。当我打印它的描述时,它会打印uiwebview描述,但它是NSObjec
这里呢 发生了什么事 这就是它崩溃的地方
-(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_合成_SINGLETON_
//
// 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)
//
//CWLSynthesisingleton.h
//爱的可可豆
//
//马特·加拉赫于2011年8月23日创作。
//版权所有(c)2011马特·加拉赫。版权所有。
//
//允许以任何形式免费使用此源代码文件
//项目,商业或其他,完全由您承担风险,条件
//源代码的任何重新分发(部分或全部)都必须保留
//本版权及许可公告。编译项目中的属性是
//感激但不是必需的。
//
#进口
#使用访问器(classname,accessorMethodName)为类定义CWL\u DECLARE\u SINGLETON\u\
+(类名*)accessorMethodName;
#如果uu具有u特征(objc_u弧)
#定义CWL\u合成\u单例\u保留\u方法
#否则
#定义CWL\u合成\u单例\u保留\u方法\
-(id)保留\
{ \
回归自我\
} \
\
-(整数)重新计数\
{ \
返回整数最大值\
} \
\
-(单向无效)释放\
{ \
} \
\
-(id)自动释放\
{ \
回归自我\
}
#恩迪夫
#使用访问器(classname,accessorMethodName)为类定义CWL\u synthesis\u SINGLETON\u\
\
静态类名*accessorMethodName##实例=nil\
\
+(类名*)访问器方法名\
{ \
@同步(自)\
{ \
if(accessorMethodName##Instance==nil)\
{ \
accessorMethodName##实例=[super allocWithZone:NULL]\
accessorMethodName##Instance=[accessorMethodName##Instance init]\
方法交换实施(\
类_getClassMethod([accessorMethodName##实例类],@selector(accessorMethodName))\
类(getClassMethod([accessorMethodName###实例类],@selector(cwl#U无锁###accessorMethodName))\
方法交换实施(\
class_getInstanceMethod([accessorMethodName###实例类],@selector(init))\
class_getInstanceMethod([accessorMethodName###实例类],@selector(cwl_onlyniton))\
} \
} \
\
返回accessorMethodName##实例\
} \
\
+(类名*)cwl_无锁##访问器方法名\
{ \
返回accessorMethodName##实例\
} \
\
+(id)allocWithZone:(NSZone*)区域\
{ \
返回[self-accessorMethodName]\
} \
\
-(id)copyWithZone:(NSZone*)区\
{ \
回归自我\
} \
-(id)cwl_Onlyinition\
{ \
回归自我\
} \
\
CWL_合成_单态_保留_方法
#使用_访问器(classname,shared###classname)为_类定义CWL _DECLARE(单例)(classname##classname)为_类定义CWL _DECLARE(单例)
#使用_访问器(classname,shared###classname)为_类(classname)定义CWL _synthesis(单例)CWL _synthesis(单例)
我从中查看代码。好。。你为什么不能这样做呢
+(MyClass *)singleton {
static dispatch_once_t pred;
static MyClass *shared = nil;
dispatch_once(&pred, ^{
shared = [[MyClass alloc] init];
});
return shared;
}
?
()您没有对CWL\u Synthesis\u SINGLETON\u FOR\u类提供任何解释。这是一个用于创建SINGLETON的宏。您可以将失败的行包装在@try/@catch块中,并将异常记录在@catch中。我为catch上的所有异常设置了一个全局断点,这应该可以做同样的事情吗?我如何使用它?调用[MyClass singleton].property?这就是问题所在。似乎合成单例方法不是线程安全的。谢谢你给我指明了正确的方向!有关此创建单例方法的更多详细信息,请参阅。