无法在iPhone模拟器中显示内容,它崩溃,但我没有错误

时间:2014-04-23 14:05:09

标签: ios objective-c

我试图在iPhone模拟器中显示我的代码,但实际上它不起作用,不知道我错了什么。我认为我犯了一些基本的,初学者的错误,但这非常令人沮丧。我没有收到任何错误,但在我运行应用程序后它崩溃了,我在日志部分得到了这些内容:(我使用故事板和最新的Xcode版本和Cocoapods)

Terminating app due to uncaught exception  'NSUnknownKeyException', reason: '[<MainViewController 0x109f330c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key overlays.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102005495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000101d6499e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000102089919 -[NSException raise] + 9
    3   Foundation                          0x0000000101945530 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x0000000102001400 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x0000000100b6c8a6 -[UINib instantiateWithOwner:options:] + 1131
    6   UIKit                               0x0000000100a06b0c -[UIViewController _loadViewFromNibNamed:bundle:] + 245
    7   UIKit                               0x0000000100a07149 -[UIViewController loadView] + 112
    8   UIKit                               0x0000000100a073b7 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x0000000100a07777 -[UIViewController view] + 29
    10  UIKit                               0x000000010094796b -[UIWindow addRootViewControllerViewIfPossible] + 58
    11  UIKit                               0x0000000100947c70 -[UIWindow _setHidden:forced:] + 282
    12  UIKit                               0x0000000100950ffa -[UIWindow makeKeyAndVisible] + 51
    13  UIKit                               0x000000010090cc98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
    14  UIKit                               0x0000000100910a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
    15  UIKit                               0x0000000100921d4c -[UIApplication handleEvent:withNewEvent:] + 3189
    16  UIKit                               0x0000000100922216 -[UIApplication sendEvent:] + 79
    17  UIKit                               0x0000000100912086 _UIApplicationHandleEvent + 578
    18  GraphicsServices                    0x000000010338a71a _PurpleEventCallback + 762
    19  GraphicsServices                    0x000000010338a1e1 PurpleEventCallback + 35
    20  CoreFoundation                      0x0000000101f87679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    21  CoreFoundation                      0x0000000101f8744e __CFRunLoopDoSource1 + 478
    22  CoreFoundation                      0x0000000101fb0903 __CFRunLoopRun + 1939
    23  CoreFoundation                      0x0000000101fafd83 CFRunLoopRunSpecific + 467
    24  UIKit                               0x00000001009102e1 -[UIApplication _run] + 609
    25  UIKit                               0x0000000100911e33 UIApplicationMain + 1010
    26  GPUCoco                             0x0000000100001ed3 main + 115
    27  libdyld.dylib                       0x00000001040465fd start + 1
    28  ???                                 0x0000000000000001 0x0 + 1
)

这是我的MainViewController.h

#import <UIKit/UIKit.h>
#import "TablViewCell.h"
#import <GPUImage.h>
@interface MainViewController : UIViewController {
    NSMutableArray *filterNames;
}

//- (void) overlayFilter1;
//- (void) coolingLookup;

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UITableView *filtersTable;

- (IBAction)filters:(id)sender;

//- (IBAction)overlays:(id)sender;

- (IBAction)undo:(id)sender;

@end

MainViewController.m

#import "MainViewController.h"

    @interface MainViewController ()

    @end

    @implementation MainViewController

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        filterNames = [[NSMutableArray alloc] init];
         [self coolingLookup];
    }


    //get number of sections in tableView from challenges array
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }

    //get number of rows by counting number of challenges
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return filterNames.count;
    }


    //setup cells in tableView
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        //setup cell
        static NSString *CellIdentifier = @"TablViewCell";
        TablViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        NSDictionary *filteredDictionary = [filterNames objectAtIndex:indexPath.row];

        cell.imageFilename.text = [filteredDictionary objectForKey:@"imagefilename"];
        cell.filteredImage.image = [filteredDictionary objectForKey:@"filteredImage"];

        return cell;
    }


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSDictionary *filteredDictionary = [filterNames objectAtIndex:indexPath.row];
        _imageView.image = [filteredDictionary objectForKey:@"filteredImage"];
    }

    /*
     #pragma mark - Navigation

     // In a storyboard-based application, you will often want to do a little preparation before navigation
     - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
     {
     // Get the new view controller using [segue destinationViewController].
     // Pass the selected object to the new view controller.
     }
     */



    /*
     **********************************************************************************************
     FILTERS
     **********************************************************************************************
     */
    - (void) coolingLookup {
        UIImage *filteredimage;
        NSString *filename = @"lookup_cooling.png";

        GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:_imageView.image];

        GPUImagePicture *lookupImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:filename]];
        GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init];
        [stillImageSource addTarget:lookupFilter];
        [lookupImageSource addTarget:lookupFilter];

        [stillImageSource processImage];
        [lookupImageSource processImage];
        [lookupFilter imageFromCurrentFramebuffer]; // megvaltozott a class neve
        filteredimage = [lookupFilter imageFromCurrentFramebuffer];

        NSDictionary *filteredDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:filteredimage, @"filteredImage", filename, @"filename", nil];

        [filterNames insertObject:filteredDictionary atIndex:0];

        [_filtersTable reloadData];
    }

    //    /*
    //     **********************************************************************************************
    //     OVERLAYS
    //     **********************************************************************************************
    //     */
    //    - (void) overlayFilter1 {
    //        NSString *filename = @"fujiFrame.png";
    //        
    //        GPUImageMultiplyBlendFilter *overlayBlendFilter = [[GPUImageMultiplyBlendFilter alloc] init];
    //        GPUImagePicture *pic1 = [[GPUImagePicture alloc] initWithImage:_imageView.image];
    //        GPUImagePicture *pic2 = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:filename]];
    //        
    //        [pic1 addTarget:overlayBlendFilter];
    //        [pic1 processImage];
    //        [pic2 addTarget:overlayBlendFilter];
    //        [pic2 processImage];
    //        
    //       UIImage *blendedImage = [overlayBlendFilter imageFromCurrentFramebufferWithOrientation::_imageView.image.imageOrientation];
    //        
    //        NSDictionary *filteredDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:blendedImage, @"filteredImage", filename, @"filename", nil];
    //        
    //        [filterNames insertObject:filteredDictionary atIndex:0];
    //        
    //        [_filtersTable reloadData];
    //    }

            - (IBAction)undo:(id)sender {
                _imageView.image = [UIImage imageNamed:@"demo01.png"];
                [filterNames removeAllObjects];
                [self coolingLookup];
            }

    //        - (IBAction)overlays:(id)sender {
    //            [filterNames removeAllObjects];
    //            [self overlayFilter1];
    //        }

            - (IBAction)filters:(id)sender {
                [filterNames removeAllObjects];
                [self coolingLookup];
            }
            - (void) applyFilter:(NSIndexPath *)indexPath {

                if (indexPath.row == 0) {
                    [self coolingLookup];
                }
            }
    @end

TablViewCell.h

#import <UIKit/UIKit.h>
@interface TablViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *filteredImage;
@property (weak, nonatomic) IBOutlet UITextField *imageFilename;
@end

TablViewCell.m

#import "TablViewCell.h"

@implementation TablViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

3 个答案:

答案 0 :(得分:0)

这是您复制粘贴或编辑连接到IBOutlet的类时遇到的常见错误。很可能是插座与代码之间的连接断开,这意味着您已在故事板上创建了一个插座,然后手动删除了代码中的属性。

该异常确实告诉你出了什么问题。故事板中的连接是在您选择的视图控制器中查找overlay属性,但由于它不存在,它会崩溃。

因此,请查看故事板上的视图控制器,然后尝试控制+单击上的所有元素并找到叠加连接。删除它,代码应该运行。

还要检查为视图控制器选择的类及其上的所有视图。您可以在Interface Builder中找到它。这也可能是导致崩溃的原因。

答案 1 :(得分:-1)

在Xcode中,当您查看故事板时,请转到实用程序栏(右侧),找到Connections检查器并检查连接是否断开。这真的是最容易出问题的。

答案 2 :(得分:-1)

我认为问题出在你的cellForRowAtIndexPath中,在这一行:

NSDictionary *filteredDictionary = [filterNames objectAtIndex:indexPath.row];

NSDictionary在特定索引处没有对象,而是具有键值对的对象。 将filteredDictionary更改为NSArray,或者将您在filteredDictionary中查找值的方式更改为

[filteredDictionary objectForKey:somekey];