NNPickerController 1.0.1

NNPickerController 1.0.1

测试已测试
语言 Obj-CObjective C
许可 MIT
发布上次发布2015年3月

numa08维护。



NNPickerController 是一个 UI 库。应用程序用户可以通过此 UI 选择元素之一。

用法

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

实现

在您的 UIViewController 中,您需要编写相应的代码:

NSArray *elementsArray ... // Tha element will be picked by PickerController
// Allocate and Initialize

NNPickerController *picker = [[NNPickerController alloc] init];

// Picker's cancel button was clicked handler;
picker.cancelHandler = ^(NNPickerController *picker) {
    [picker dismissPickerController];
};

// Element was picked handler
picker.finishPickingHandler = ^(NNPickerController *picker, UITableView *tableView,NSIndexPath *indexPath){
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.elementLabel.text = elementsArray[indexPath.row];
    [picker dismissPickerController];
};

// Configuration for Picker Controller
[picker setNumberOfSection:^NSInteger{
    return 1;
} withNumberOfRow:^NSInteger(NSInteger section) {
    return elementsArray.count;
} withCellForRowAtIndexPath:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
    NSString *cellIdentifier = [NSString stringWithFormat:@"cell%@/%@", @(indexPath.row),@(indexPath.section)];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell != nil) {
        return cell;
    }
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    cell.textLabel.text = elementsArray[indexPath.row];
    if (indexPath.row == 0) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    return cell;
}];

// show picker controller
[picker showPickerControllerForViewController];

安装

作者

numa08, [email protected]

许可

NNPickerController 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。