gpt4 book ai didi

ios - 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序?有什么线索吗?

转载 作者:行者123 更新时间:2023-11-29 03:40:45 26 4
gpt4 key购买 nike

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

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

最佳答案

正如您在评论中提到的,您只是放置 UIPickerView...但是要使用选择器 View ,您需要设置像 UITableView 这样的数据源,并且必须实现所有@required 方法。

picker view的数据源协议(protocol)中,有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;

因此,您需要在 Controller 中实现上述两个方法(例如MainViewController)。并且不要忘记将此类设置为 UIPicker View 的委托(delegate)和数据源,如下所示

MainViewControllerViewDidLoad

self.yourPickerView.datasource = self;
self.yourPickerView.delegate = self;

关于ios - 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序?有什么线索吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18504321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com