2011-03-14 47 views
0

嗨大家好,我在我的高中做獨立研究iphone編程。我從老師那裏得到了一本書「Head First Iphone Programming」。我沒有任何問題地完成了第一課(帶有按鈕的Hello World),但現在我已經進入了第二課。這是一個使用UIPickerview顯示選項的Twitter應用程序。我一直沒有能夠在UIPickerview上看到任何東西。iPhone從書籍編程。 「InstatwitViewController」的不完整實現

我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並右鍵單擊拾取器,並將數據源拖到文件所有者,就像本書告訴我 然後當我運行它..我得到黑屏然後沒有。

我的繼承人調試

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

任何幫助將是巨大的,因爲這是一類,和IM一個完整的noob,我一直呆在這裏了一個月左右。

謝謝

+0

你說的代碼片段就是你的InstantwitViewController.h,它與你說的是InstantwitViewController.m的代碼片段是重複的。你能發佈真正的.h文件嗎? – Walter 2011-03-15 00:44:28

+0

@Walter謝謝你的接受,我修正了它。 – user659680 2011-03-15 14:23:28

回答

2

您在委託方法中缺少一個空格。使用:

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

感謝您的提示,但是當我建立我的程序,它會得到3個警告A)類'InstatwitViewController'的不完整實現' B)未找到'-pickerView:numberOfRowsInComponent:'方法定義 C)類'InstatwitViewController'不完全實現'UIPickerViewDataSource'協議 這些讓我覺得我的.m文件中的某些內容不正確,或者在我的IB中,當我按住Control鍵並點擊拖動時 – user659680 2011-03-15 14:36:53

+0

.h文件中也存在錯誤。你有它實現它應該是。我很確定這些東西都是區分大小寫的。 – gnuchu 2011-03-15 14:53:40