开发者

UIPickerView only displays one component; should display two

开发者 https://www.devze.com 2023-03-17 02:47 出处:网络
Have a UIPicker which should display two components (columns in the picker view), but is only displaying one.

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


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号