2014-04-23 56 views
0

我試圖在iPhone模擬器中顯示我的代碼,但實際上它不工作,不知道我錯了什麼。我想我犯了一些基本的,初學者的錯誤,但這很令人沮喪。我沒有得到任何錯誤,但在我運行應用程序崩潰,並讓我在日誌節這些行:(我用故事板和最新的Xcode版本的CocoaPods)無法顯示在iPhone模擬器中的內容,它崩潰,但我得到沒有錯誤

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 
+2

更可能的,你的故事板掛鉤起來觀點,即不存在了網點。 –

+0

我註釋了一個按鈕,它是方法,我認爲其他的東西都必須存在。 – rihe

+1

導致崩潰的插座叫做'overlays'。我敢打賭,你以前曾經有一個名爲'overlays'的屬性,並且在不刪除故事板中的連接的情況下將其刪除。 –

回答

0

這是您複製粘貼或編輯與IBOutlet s連接的類時得到的常見錯誤。插座和代碼之間的連接很可能已斷開,這意味着您已在故事板上創建插座,然後手動刪除代碼中的屬性。

這個例外實際上告訴你什麼是錯的。故事板中的連接在您選擇的視圖控制器中查找overlay屬性,但因爲它不存在,所以它崩潰。

所以看看故事板上的視圖控制器,並嘗試控制+點擊它的所有元素,並找到重疊連接。刪除它,代碼應該運行。

同時檢查您爲視圖控制器及其所有視圖選擇的類。你可以在Interface Builder中找到它。這也可能是導致事故的原因。

+0

文本字段中存在未提供的屬性。我刪除了它,但又崩潰並將我放回GPUImagePicture.m。並得到這在日誌部分:2014-04-23 16:50:33.551 GPUCoco [1758:60b] ***斷言失敗 - [GPUImagePicture initWithCGImage:smoothScaleOutput:],/ Users/szabolcsvarga/Documents/GPU/GPUCoco/Pods/GPUImage/framework/Source/iOS/GPUImagePicture.m:72 (lldb) – rihe

+0

如果你檢查你發佈的文件中的斷言('GPUImagePicture.m'),它會給你這個: 'NSAssert widthOfImage> 0 && heightOfImage> 0,@「通過的圖像不能爲空 - 它應該至少1px高,寬」);' 所以很明顯,您發送到此方法的圖像是0px寬度或0px高度或兩者)。檢查CGImage是否正確創建。如果沒有代碼,我無法確定確切的問題。 – Legoless

-1

在Xcode中,當你在看故事板去酒吧公用事業(正確的),發現有連接督察和檢查損壞的連接。這確實是最有可能成爲問題的。

+0

我沒有看到那裏的連接斷開。它應該是什麼樣子?它是否標有紅色? – rihe

+0

在參考插座中搜索「疊加」。您沒有任何名爲「疊加」的IBOutlet,但看起來像Xcode不這麼認爲。查找哪個視圖已連接到「疊加」並刪除此連接。 – user2260054

+0

我已經把它刪除了一點。我已經刪除了故事板中的按鈕以及它所連接的類中的屬性。現在在連接檢查器和頭文件中的其他地方沒有任何名爲'overlay'的東西,但仍然崩潰。 – rihe

-1

我認爲這個問題是在你的cellForRowAtIndexPath,在這一行:

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

的NSDictionary不具有在特定的索引對象,而是它有鍵值對的對象。 要麼改變filteredDictionary是一個NSArray,或者改變您在filteredDictionary值的方式是

[filteredDictionary objectForKey:somekey]; 
相關問題