简体   繁体   English

使用UIPicker在UITableViewController中创建所需的行数

[英]Using UIPicker to create desired number of rows in UITableViewController

I have a view with my UIPicker that will push to my UITableViewController when my start button is pressed. 我有一个带有UIPicker的视图,当按下启动按钮时,该视图将推送到UITableViewController

I want to create a certain number of rows per section in my UITableViewController from my UIPicker . 我想从我的UIPicker UITableViewController每个节中创建一定数量的行。

Here is the relevant code. 这是相关的代码。 I'm not getting errors. 我没有错误。 My UITableViewController just doesn't have any rows in its sections. 我的UITableViewController中没有任何行。 Any advice or examples on how I could get this to work would be great. 关于如何使它起作用的任何建议或示例都很好。 Or if someone knows a better way of going about this that would be equally appreciated. 或者,如果有人知道解决此问题的更好方法,也将同样受到赞赏。

from PushView.m 从PushView.m

    @interface WorkoutPushViewController ()
{
NSArray *_PickerData;
}

- (void)viewDidLoad {
[super viewDidLoad];

//picker
_PickerData = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
self.setsPicker.dataSource = self;
self.setsPicker.delegate = self;
}

from TableView.h 从TableView.h

    @interface TableViewController : UITableViewController
    @property (nonatomic, retain) PushViewController *pushReference;
    @end

from TableView.m 从TableView.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return ([self.pushReference.setsPicker selectedRowInComponent:0]+1);
// +1 because index 0 is 1 row. 
}

Thanks! 谢谢!

As Nitin Gohel said: In your TableView.h 正如Nitin Gohel所说:在您的TableView.h中

@interface TableViewController : UITableViewController
@property (nonatomic) NSInteger numberOfRows;
@end

And in your TableView.m 并在您的TableView.m中

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.numberOfRows;
}

Don't forget to assign the value of number of rows when your start button is tapped. 轻按“开始”按钮时,不要忘记分配行数的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不论行数如何,使用uitableviewcontroller时如何在屏幕底部添加按钮? - how to add a button to bottom of screen when using a uitableviewcontroller irrespective of number of rows? 使用静态UITableViewController创建两个部分,其中第一部分具有非静态单元格数 - Using a static UITableViewController to create two sections with the first section having a non-static number of cells 如何使用UITableViewController创建布局(作为图像) - how to create the layout (attached as image) using UITableViewController 带有UIPicker选项的UITableView行选择 - UITableView Rows selection with UIPicker Option 在UITableViewController中对行进行排序 - Sorting rows in UITableViewController UIPicker使用JSON的对象和键 - UIPicker with object and keys using JSON UITableViewController复制行? - UITableViewController duplicating rows? 以编程方式将行插入到UITableViewController - Programmatically insert rows to UITableViewController 是否可以使用故事板使用UIViewController而不是UITableViewController创建静态表? - Is it possible to use storyboards to create a static table using UIViewController instead of UITableViewController? 如何使用New> File…模板“向导”在Xcode 6中创建UITableViewController - How to create UITableViewController in Xcode 6 using New>File… template “wizard”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM