0

我有一个 NavigationController -> UIViewController -> UIWebView

我有一个从 tableViewController 到 NavigationController 的模态序列。

每当我执行此 segue 时,应用程序就会崩溃。我没有在控制器中编写任何代码,只是简单地在情节提要中放置了一个 uiwebview。如果我删除 uiwebview,segue 运行得很好。

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

见这里http://cl.ly/GZWJ 截屏
和这里http://cl.ly/Gaig 截屏发生了 什么?

这是它崩溃的地方。

-(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)
4

1 回答 1

1

我查看了来自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;
}

?

()

于 2012-05-12T21:43:22.000 回答