首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我加载包含webview的视图控制器时,iphone应用程序崩溃

当我加载包含webview的视图控制器时,iphone应用程序崩溃
EN

Stack Overflow用户
提问于 2012-05-13 05:22:22
回答 1查看 589关注 0票数 0

我有一个NavigationController -> UIViewController -> UIWebView

我有一个从tableViewController到NavigationController的模式段。

每当我执行此段时,应用程序都会崩溃。我没有在控制器中编写代码,只是简单地在故事板中放置了一个uiwebview。如果我移除uiwebview,则segue运行得很好。

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

查看此处http://cl.ly/GZWJ

还有这里的http://cl.ly/Gaig

这是怎么回事?

这就是它崩溃的地方。

代码语言:javascript
复制
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"webView" sender:self];
}

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

代码语言:javascript
复制
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宏

代码语言:javascript
复制
//
//  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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-13 05:43:22

我看了http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html的代码。好吧..。为什么你不能让单件像这样:

代码语言:javascript
复制
+(MyClass *)singleton {
 static dispatch_once_t pred;
 static MyClass *shared = nil;

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

(src)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10567500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档