Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MainPageCollectionViewConrtoller\u setViewDelegate::发送到实例0x7faa7ae39160的选择器无法识别_Ios_Swift_Core Data_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios MainPageCollectionViewConrtoller\u setViewDelegate::发送到实例0x7faa7ae39160的选择器无法识别

Ios MainPageCollectionViewConrtoller\u setViewDelegate::发送到实例0x7faa7ae39160的选择器无法识别,ios,swift,core-data,uicollectionview,uicollectionviewcell,Ios,Swift,Core Data,Uicollectionview,Uicollectionviewcell,我正在编写一个简单的程序,到现在为止,它只应该显示一个简单的uicollectionview。单元格包含标签和图像视图。图像存储在CoreData中。还有一个代码表示没有可用数据的时间。 但这给了我一个错误: 2015-06-16 23:03:15.694 What Can I Wear[16167:2033274] -[What_Can_I_Wear.MainPageCollectionViewConrtoller _setViewDelegate:]: unrecognized se

我正在编写一个简单的程序,到现在为止,它只应该显示一个简单的uicollectionview。单元格包含标签和图像视图。图像存储在CoreData中。还有一个代码表示没有可用数据的时间。 但这给了我一个错误:

    2015-06-16 23:03:15.694 What Can I Wear[16167:2033274] -[What_Can_I_Wear.MainPageCollectionViewConrtoller _setViewDelegate:]: unrecognized selector sent to instance 0x7ff1f2c30ba0
2015-06-16 23:03:15.697 What Can I Wear[16167:2033274] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[What_Can_I_Wear.MainPageCollectionViewConrtoller _setViewDelegate:]: unrecognized selector sent to instance 0x7ff1f2c30ba0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000106b24c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010868fbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000106b2c0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000106a8213c ___forwarding___ + 988
    4   CoreFoundation                      0x0000000106a81cd8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001074f47bf -[UIViewController setView:] + 458
    6   UIKit                               0x0000000107a09b27 -[UICollectionViewController setView:] + 90
    7   Foundation                          0x0000000106f42b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    8   CoreFoundation                      0x0000000106a6cd50 -[NSArray makeObjectsPerformSelector:] + 224
    9   UIKit                               0x000000010769b52b -[UINib instantiateWithOwner:options:] + 1506
    10  UIKit                               0x00000001074f3718 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
    11  UIKit                               0x00000001074f3d08 -[UIViewController loadView] + 109
    12  UIKit                               0x0000000107a097c1 -[UICollectionViewController loadView] + 235
    13  UIKit                               0x00000001074f3f79 -[UIViewController loadViewIfRequired] + 75
    14  UIKit                               0x000000010752401b -[UINavigationController _layoutViewController:] + 44
    15  UIKit                               0x0000000107524565 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 216
    16  UIKit                               0x0000000107524664 -[UINavigationController _startTransition:fromViewController:toViewController:] + 92
    17  UIKit                               0x0000000107525448 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
    18  UIKit                               0x0000000107525f0e -[UINavigationController __viewWillLayoutSubviews] + 43
    19  UIKit                               0x0000000107670715 -[UILayoutContainerView layoutSubviews] + 202
    20  UIKit                               0x0000000107443a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    21  QuartzCore                          0x000000010b224ec2 -[CALayer layoutSublayers] + 146
    22  QuartzCore                          0x000000010b2196d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    23  QuartzCore                          0x000000010b219546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    24  QuartzCore                          0x000000010b185886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    25  QuartzCore                          0x000000010b186a3a _ZN2CA11Transaction6commitEv + 462
    26  UIKit                               0x00000001073c1a2d -[UIApplication _reportMainSceneUpdateFinished:] + 44
    27  UIKit                               0x00000001073c26f1 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2648
    28  UIKit                               0x00000001073c10d5 -[UIApplication workspaceDidEndTransaction:] + 179
    29  FrontBoardServices                  0x000000010a19f5e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
    30  CoreFoundation                      0x0000000106a5841c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    31  CoreFoundation                      0x0000000106a4e165 __CFRunLoopDoBlocks + 341
    32  CoreFoundation                      0x0000000106a4df25 __CFRunLoopRun + 2389
    33  CoreFoundation                      0x0000000106a4d366 CFRunLoopRunSpecific + 470
    34  UIKit                               0x00000001073c0b42 -[UIApplication _run] + 413
    35  UIKit                               0x00000001073c3900 UIApplicationMain + 1282
    36  What Can I Wear                     0x000000010652b387 main + 135
    37  libdyld.dylib                       0x0000000108de7145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
这是我的密码: AppDelegate.swift

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        // Saves changes in the application's managed object context before the application terminates.
        self.saveContext()
    }

    // MARK: - Core Data stack

    lazy var applicationDocumentsDirectory: NSURL = {
        // The directory the application uses to store the Core Data store file. This code uses a directory named "com.atrin.ios.whattowear.TEST" in the application's documents Application Support directory.
        let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
        return urls[urls.count-1] as! NSURL
        }()

    lazy var managedObjectModel: NSManagedObjectModel = {
        // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
        let modelURL = NSBundle.mainBundle().URLForResource("What_Can_I_Wear", withExtension: "momd")!
        return NSManagedObjectModel(contentsOfURL: modelURL)!
        }()

    lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
        // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
        // Create the coordinator and store
        var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
        let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("What_Can_I_Wear.sqlite")
        var error: NSError? = nil
        var failureReason = "There was an error creating or loading the application's saved data."
        if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
            coordinator = nil
            // Report any error we got.
            var dict = [String: AnyObject]()
            dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
            dict[NSLocalizedFailureReasonErrorKey] = failureReason
            dict[NSUnderlyingErrorKey] = error
            error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
            // Replace this with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            NSLog("Unresolved error \(error), \(error!.userInfo)")
            abort()
        }

        return coordinator
        }()

    lazy var managedObjectContext: NSManagedObjectContext? = {
        // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
        let coordinator = self.persistentStoreCoordinator
        if coordinator == nil {
            return nil
        }
        var managedObjectContext = NSManagedObjectContext()
        managedObjectContext.persistentStoreCoordinator = coordinator
        return managedObjectContext
        }()

    // MARK: - Core Data Saving support

    func saveContext () {
        if let moc = self.managedObjectContext {
            var error: NSError? = nil
            if moc.hasChanges && !moc.save(&error) {
                // Replace this implementation with code to handle the error appropriately.
                // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                NSLog("Unresolved error \(error), \(error!.userInfo)")
                abort()
            }
        }
    }

}
MainCollectionViewControllerCell.swift:

import Foundation
import UIKit

class MainCollectionViewControllerCell : UICollectionViewCell {
    required init(coder aDecoder: NSCoder) {
        super.init(coder : aDecoder);
    }

    @IBOutlet weak var imageView:UIImageView!
    @IBOutlet weak var name: UILabel!
}
MainPageCollectionViewController.swift:

import Foundation
import UIKit
import CoreData

class MainPageCollectionViewConrtoller: UICollectionViewController,UICollectionViewDataSource {

    let managedObject = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
    private let reuseIdentifier = "Cloth Cell"

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) ->UICollectionViewCell {
        let cell :MainCollectionViewControllerCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! MainCollectionViewControllerCell

        let models :[Model] = DataModelController.getModels(managedObject!) as [Model]

        if(models.count == 0){
            let url = NSURL(string: "http://epaper2.mid-day.com/gallery.aspx?ed_date=2015-jun-14&ed_code=252&ed_check=adpath")
            let data = NSData(contentsOfURL: url!)
            cell.imageView.image = UIImage(data: data!)
            cell.name.text = "Nothing Available"
            return cell
        }


        let model : Model = models[indexPath.row]
        cell.name.text = (model as Model).name
        let image : NSData = (((model as Model).images.allObjects as Array)[0] as! ClothImages).image
        cell.imageView.image = UIImage(data: image) as UIImage!
        return cell
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
MainPageCollectionViewController右舷代码:

<scene sceneID="Kn7-pO-JTm">
            <objects>
                <collectionViewController id="FVt-vB-R91" customClass="MainPageCollectionViewConrtoller" customModule="What_Can_I_Wear" customModuleProvider="target" sceneMemberID="viewController">
                    <collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="FJw-a0-Kgb" customClass="MainPageCollectionViewConrtoller" customModule="What_Can_I_Wear" customModuleProvider="target">
                        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                        <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="CFC-BY-8kT">
                            <size key="itemSize" width="164" height="207"/>
                            <size key="headerReferenceSize" width="0.0" height="0.0"/>
                            <size key="footerReferenceSize" width="0.0" height="0.0"/>
                            <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
                        </collectionViewFlowLayout>
                        <cells>
                            <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="Vwl-K3-92g" customClass="MainCollectionViewControllerCell" customModule="What_Can_I_Wear" customModuleProvider="target">
                                <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
                                <autoresizingMask key="autoresizingMask"/>
                                <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                    <rect key="frame" x="0.0" y="0.0" width="164" height="207"/>
                                    <autoresizingMask key="autoresizingMask"/>
                                    <subviews>
                                        <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ltQ-Ta-9Jq">
                                            <rect key="frame" x="0.0" y="0.0" width="164" height="170"/>
                                        </imageView>
                                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RKA-CP-FuB">
                                            <rect key="frame" x="59" y="178" width="46" height="21"/>
                                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                            <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                                            <nil key="highlightedColor"/>
                                        </label>
                                    </subviews>
                                    <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                                </view>
                                <connections>
                                    <outlet property="imageView" destination="ltQ-Ta-9Jq" id="D0d-mB-Ybk"/>
                                    <outlet property="name" destination="RKA-CP-FuB" id="n5I-T9-OAf"/>
                                </connections>
                            </collectionViewCell>
                        </cells>
                    </collectionView>
                    <navigationItem key="navigationItem" id="Tdr-mU-YJp">
                        <barButtonItem key="leftBarButtonItem" style="plain" id="js7-jN-Ht7">
                            <button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="YkG-72-dmE">
                                <rect key="frame" x="-23" y="-15" width="133" height="30"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <state key="normal" title="Menu">
                                    <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                            </button>
                        </barButtonItem>
                    </navigationItem>
                </collectionViewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="Ek1-0V-iZ8" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1256" y="1014"/>
        </scene>

我在这个错误中工作了两天,但我还没有找到解决办法。
请提供帮助。

您可以添加一个符号断点,该断点在发生此情况时停止。5点左右看一看视频。这为您提供了更多的信息。我找不到真正的原因,但通过创建一个具有相同内容的新项目来修复。因此,这可能是项目配置中的一个错误。

请将此简化为一个合理的最小示例