UIPickerView只显示一个组件;应该显示两个

发布于 2024-11-18 05:53:11 字数 1893 浏览 3 评论 0原文

有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆兒滾 2024-11-25 05:53:11

您不会在第二个组件的 pickerView:titleForRow:inComponent: 方法中返回值。

if (component == 0) {
    return [activities_ objectAtIndex:row];
} else {
    [feelings_ objectAtIndex:row];
}

你应该做

return [feelings_ objectAtIndex:row];

You are not returning the value in the pickerView:titleForRow:inComponent: method for the second component.

if (component == 0) {
    return [activities_ objectAtIndex:row];
} else {
    [feelings_ objectAtIndex:row];
}

You should do

return [feelings_ objectAtIndex:row];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文