Cocoa touch 选择器中的第二个组件未正确实例化

Cocoa touch 选择器中的第二个组件未正确实例化,cocoa-touch,xcode,uikit,Cocoa Touch,Xcode,Uikit,我正在使用picker处理简单实用程序应用程序,但消息输出不正确。第二个组件没有正确实例化,而是输出“我在睡觉,感觉很开心。”之类的内容,而输出“我在睡觉,感觉InstatwitViewController很开心” 一切都已在IB中连接 你能告诉我怎么了吗 以下是.h文件: #import <UIKit/UIKit.h> @interface InstatwitViewController : UIViewController <UIPickerViewDataSource,

我正在使用picker处理简单实用程序应用程序,但消息输出不正确。第二个组件没有正确实例化,而是输出“我在睡觉,感觉很开心。”之类的内容,而输出“我在睡觉,感觉InstatwitViewController很开心”

一切都已在IB中连接

你能告诉我怎么了吗

以下是.h文件:

#import <UIKit/UIKit.h>

@interface InstatwitViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate>
{
    IBOutlet UIPickerView *tweetPicker;
    NSArray* activities;
    NSArray* feelings;
}

@property (nonatomic,retain)UIPickerView* tweetPicker; 
- (IBAction) sendButtonTapped:(id)sender;

@end

如果我们修复缩进,您的
sendbuttonattaped:
如下所示:

- (IBAction) sendButtonTapped:(id)sender
{
    NSString* themessage = [NSString stringWithFormat:@"I'm %@ and feeling %@ about it.",
                            [activities objectAtIndex:[tweetPicker selectedRowInComponent:0]]];
    [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]];
    NSLog(themessage);
}
换句话说,括号嵌套错误,永远不会将“感觉”传递给格式字符串。你很幸运,它没有撞到你

- (IBAction) sendButtonTapped:(id)sender
{
    NSString* themessage = [NSString stringWithFormat:@"I'm %@ and feeling %@ about it.",
                            [activities objectAtIndex:[tweetPicker selectedRowInComponent:0]]];
    [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]];
    NSLog(themessage);
}