0

NavigationController -> UIViewController -> UIWebView があります

tableViewController から NavigationController へのモーダル セグエがあります。

このセグエを実行するたびに、アプリケーションがクラッシュします。コントローラーにコードを記述せず、ストーリーボードに uiwebview を配置しただけです。uiwebview を削除すると、セグエは問題なく動作します。

デバッガーは、シングルトン オブジェクト「CoData.m」のシングルトン作成行で停止します。そして、その説明を印刷すると、uiwebview の説明が印刷されますが、これは NSObject 型のカスタム クラスです。

ここhttp://cl.ly/GZWJ スクリーンショット
とここhttp://cl.ly/Gaig スクリーンショットを参照してください 。

これがクラッシュする場所です。

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

EDIT** 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

AND 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 に答える