0

这是我现在正在使用的代码,但仍然出现各种错误:

No visible @interface for 'HomeViewController' declares the selector 'getCount' 

/Volumes/Lex/HomeViewController.h:12:12: Required for direct or indirect protocol 'UIPickerViewDataSource'
/Volumes/Lexar/HomeViewController.m:15:17: Incomplete implementation

我的代码(.m 文件)

- (void)viewDidLoad
{
    [super viewDidLoad];

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user: %@" , currentUser.username);
    }
    else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];

        self.pickerView.dataSource = self;
        self.pickerView.delegate = self;
    }
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:  (NSInteger)component
{
    if ([self getCount] == 0)
        return 1;
    return [self getCount];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:     (NSInteger)component reusingView:(UIView *)view {
    if ([self getCount] == 0)
        return nil;
}

- (IBAction)logout:(id)sender {
    [PFUser logOut];
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}
@end

和标题

/// .h controller

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface HomeViewController : UIViewController <UIPickerViewDataSource,    UIPickerViewDelegate>

@property (strong, nonatomic) IBOutlet UIPickerView *pickerView;

- (IBAction)logout:(id)sender;

@end
4

1 回答 1

1

正如您在评论中提到的那样,您只是在放置UIPickerView......但是要使用选择器视图,您需要设置 DatasourceUITableView并且必须实现所有@required方法。

在picker view的数据源协议中,有2个@required方法

// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

所以你需要在你的控制器中实现以上两种方法(比如MainViewController)。并且不要忘记将此类设置为 UIPicker 视图的委托和数据源,如下所示

ViewDidLoadMainViewController

self.yourPickerView.datasource = self;
self.yourPickerView.delegate = self;
于 2013-08-29T07:37:12.687 回答