简体   繁体   中英

iphone app crashes when i load a viewcontroller containing webview

I have a NavigationController -> UIViewController -> UIWebView

I have a modal segue from a tableViewController to the NavigationController.

whenever i perform this segue the Application crashes. I've written no code in the controller, just simply placed a uiwebview in the storyboard. If i remove the uiwebview the segue runs just fine.

The debugger stops at the singleton creation line in my singleton object "CoData.m". And when i print a description of it it prints a uiwebview description, but it's a custom class of type NSObject.

see here http://cl.ly/GZWJ 屏幕截图
and here http://cl.ly/Gaig 屏幕截图 What is happening?

This is where it crashes.

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

EDIT** abridged contents of 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 the CWL_SYNTHESIZE_SINGLETON_FOR_CLASS macro

//
//  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)

I looked at the code from http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html . well.. any reason why you can't make singleton like this:

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

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

?

( src )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM