iPhone编程从书。类'InstatwitViewController'的实现不完整

时间:2011-03-14 22:58:59

标签: iphone xcode implementation

嘿大家,我在高中做独立研究iphone编程。我从老师那里得到了一本书“Head First Iphone Programming”。我完成了第一课(带按钮的hello world),没有任何问题,但现在我进入了第二课。这是一个使用UIPickerview显示选项的twitter应用程序。我无法在UIPickerview上看到任何内容。

我的InstatwitViewController.h看起来像:

   #import <UIKit/UIKit.h>
@interface InstatwitViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
     NSArray* activities;
     NSArray* feelings;
}
@end

我的InstaTwitViewController.m看起来像:

#import "InstatwitViewController.h"

@implementation InstatwitViewController

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerViewNumberOfRowsInComponent : (NSInteger)component {
    if (component == 0) {
        return [activities count];
    }
    else {
        return [feelings count];
    }
}

和....

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    activities = [[NSArray alloc] initWithObjects:@"Sleeping", @"eating", @"working", @"thinking", @"crying", @"begging", @"leaving", @"shopping", @"hello worlding", nil];
    feelings = [[NSArray alloc] initWithObjects:@"awesome", @"sad", @"happy", @"ambivalent", @"nauseous", @"psyched", @"confused", @"hopeful", @"anxious", nil];
}

和....

- (void)dealloc {
    [activities release];
    [feelings release];
    [super dealloc];
}

我进入IB并右键单击选择器并将dataSource拖到文件所有者,就像书中告诉我的那样 然后,当我跑它..我有黑屏然后没有。

继承我的调试器

[Session started at 2011-03-14 18:48:17 -0400.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 10220.
2011-03-14 18:48:19.411 Instatwit[10220:207] -[InstatwitViewController pickerView:numberOfRowsInComponent:]: unrecognized selector sent to instance 0x5c164e0
2011-03-14 18:48:19.415 Instatwit[10220:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[InstatwitViewController pickerView:numberOfRowsInComponent:]: unrecognized selector sent to instance 0x5c164e0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0238c919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x024da5de objc_exception_throw + 47
    2   CoreFoundation                      0x0238e42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x022fe1b4 ___forwarding___ + 1124
    4   CoreFoundation                      0x022fdcd2 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002a7072 -[UIPickerView _delegateNumberOfRowsInComponent:] + 159
    6   UIKit                               0x0045033f -[UITable dataSourceGetRowCount] + 47
    7   UIKit                               0x004502e9 -[UITable numberOfRows] + 54
    8   UIKit                               0x0044e9d8 -[UITable floatArray:getValueCount:gapIndexCount:] + 34
    9   UIKit                               0x0034bbb5 -[UIFloatArray _setupWithDataProvider:valueIsSingleton:singletonValue:isRefresh:] + 68
    10  UIKit                               0x0034bb6b -[UIFloatArray refreshWithDataProvider:singleValue:] + 64
    11  UIKit                               0x004500d7 -[UITable setRowHeight:] + 160
    12  UIKit                               0x002a6201 -[UIPickerTable setRowHeight:] + 61
    13  UIKit                               0x004520e1 -[UITable _reloadRowHeights] + 199
    14  UIKit                               0x0044ff71 -[UITable noteNumberOfRowsChanged] + 99
    15  UIKit                               0x00454a0e -[UITable reloadData] + 439
    16  UIKit                               0x002ab301 -[UIPickerView layoutSubviews] + 4052
    17  QuartzCore                          0x0401c0d5 -[CALayer layoutSublayers] + 177
    18  QuartzCore                          0x0401be05 CALayerLayoutIfNeeded + 220
    19  QuartzCore                          0x0401b64c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 302
    20  QuartzCore                          0x0401b2b0 _ZN2CA11Transaction6commitEv + 292
    21  UIKit                               0x002b363f -[UIApplication _reportAppLaunchFinished] + 39
    22  UIKit                               0x002b3a68 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 545
    23  UIKit                               0x002bd452 -[UIApplication handleEvent:withNewEvent:] + 1958
    24  UIKit                               0x002b6074 -[UIApplication sendEvent:] + 71
    25  UIKit                               0x002baac4 _UIApplicationHandleEvent + 7495
    26  GraphicsServices                    0x02bf2afa PurpleEventCallback + 1578
    27  CoreFoundation                      0x0236ddc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    28  CoreFoundation                      0x022ce737 __CFRunLoopDoSource1 + 215
    29  CoreFoundation                      0x022cb9c3 __CFRunLoopRun + 979
    30  CoreFoundation                      0x022cb280 CFRunLoopRunSpecific + 208
    31  CoreFoundation                      0x022cb1a1 CFRunLoopRunInMode + 97
    32  UIKit                               0x002b3226 -[UIApplication _run] + 625
    33  UIKit                               0x002beb58 UIApplicationMain + 1160
    34  Instatwit                           0x00001f18 main + 102
    35  Instatwit                           0x00001ea9 start + 53
    36  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
(gdb) 

任何帮助都会很棒,因为这是一个班级,我是一个完整的菜鸟,我已经被困在这里一个月左右。

感谢

1 个答案:

答案 0 :(得分:2)

您在委托方法中缺少空格。使用:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (component == 0) {
        return [activities count];
    }
    else {
        return [feelings count];
    }
}