akkyie/AKPickerView

UITableview usage

mythodeia opened this issue · 3 comments

Hello and thanks for the great code.
Is there any way to use this in a tableview in a settings style view?
each row that consists of this control should have each own datasource,values.

again thanks for contributing

answering my own question...
i made it work by adding this:
@Property (nonatomic, strong) NSMutableArray *dataSource;
to the AKPickerView header file
and in the delegates, for example the titleForItem, i put this:
return pickerView.dataSource[item];
and it seems to work.

if you have a better way please share

thanks

Thank you for using my control!

How about subclassing UITableViewCell?
Sample code below:

//  MyTableViewCell.h

#import <UIKit/UIKit.h>

#import "AKPickerView.h"

@interface MyTableViewCell : UITableViewCell <AKPickerViewDelegate>

@property (nonatomic, strong) NSArray *objects;

// if you use Storyboard
@property (nonatomic, weak) IBOutlet AKPickerView *pickerView;

// or not
@property (nonatomic, strong) AKPickerView *pickerView;

@end
//  MyTableViewCell.m

#import "MyTableViewCell.h"

@implementation MyTableViewCell

// insert other implementations here

- (void)setObjects:(NSArray *)objects
{
    if (![_objects isEqual:objects]) {
        _objects = objects;

        [self.pickerView reloadData];
    }
}

- (NSUInteger)numberOfItemsInPickerView:(AKPickerView *)pickerView
{
    return [self.objects count];
}

- (NSString *)pickerView:(AKPickerView *)pickerView titleForItem:(NSInteger)item
{
    return [self.objects[item] description];
}

// insert other implementations here

@end

I have not tested this code yet, but I hope it helps you.

thanks a lot for your time and information and of course for making it open source.
Regards