UIPickerView只显示一个组件;应该显示两个
有一个 UIPicker 应该显示两个组件(选择器视图中的列),但只显示一个。
找不到错误;它构建正确。第二个组件为空;没有显示数据。
InstaEmailViewController.h
#import <UIKit/UIKit.h>
@interface InstaEmailViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* activities_ ;
NSArray* feelings_ ;
}
InstaEmailViewController.m
#import "InstaEmailViewController.h"
@implementation InstaEmailViewController
- (void)dealloc
{
[activities_ release];
[feelings_ release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
activities_ = [[NSArray alloc] initWithObjects:@"sleeping", @"working", @"thinking", @"crying", @"begging", @"leaving", @"shopping", @"hello worlding", nil];
feelings_ = [[NSArray alloc] initWithObjects: @"awesome", @"sad", @"ambivalent", @"nauseous",@"psyched", @"confused", @"hopeful", @"anxious", nil];
[super viewDidLoad];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) {
return [activities_ objectAtIndex:row];
} else {
[feelings_ objectAtIndex:row];
}
return nil;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component {
if (component ==0) {
return [activities_ count];
} else {
return [feelings_ count];
}
}
@end
Have a UIPicker which should display two components (columns in the picker view), but is only displaying one.
Can't find the error; it builds correctly. Second component is empty; no data displayed.
InstaEmailViewController.h
#import <UIKit/UIKit.h>
@interface InstaEmailViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* activities_ ;
NSArray* feelings_ ;
}
InstaEmailViewController.m
#import "InstaEmailViewController.h"
@implementation InstaEmailViewController
- (void)dealloc
{
[activities_ release];
[feelings_ release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
activities_ = [[NSArray alloc] initWithObjects:@"sleeping", @"working", @"thinking", @"crying", @"begging", @"leaving", @"shopping", @"hello worlding", nil];
feelings_ = [[NSArray alloc] initWithObjects: @"awesome", @"sad", @"ambivalent", @"nauseous",@"psyched", @"confused", @"hopeful", @"anxious", nil];
[super viewDidLoad];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) {
return [activities_ objectAtIndex:row];
} else {
[feelings_ objectAtIndex:row];
}
return nil;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component {
if (component ==0) {
return [activities_ count];
} else {
return [feelings_ count];
}
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会在第二个组件的
pickerView:titleForRow:inComponent:
方法中返回值。你应该做
You are not returning the value in the
pickerView:titleForRow:inComponent:
method for the second component.You should do