UITableView inside UIPickerView in iOS

I am amazed at the problem when I need to implement a selector of several types, so for this I do this:

caratFromPicker = [[UIPickerView alloc] init]; caratTable = [[UITableView alloc]initWithFrame:caratFromPicker.frame style:UITableViewStylePlain]; caratTable.delegate = self; caratTable.dataSource = self; caratTable.bounces = YES; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)]; UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-caratFromPicker.frame.size.height-50, self.view.frame.size.width, 50)]; [toolBar setBarStyle:UIBarStyleBlackOpaque]; NSArray *toolbarItems = [NSArray arrayWithObjects:doneButton, nil]; [toolBar setItems:toolbarItems]; price1.inputView = caratFromPicker; price1.inputAccessoryView = toolBar; [caratFromPicker setDataSource: self]; [caratFromPicker setDelegate: self]; caratFromPicker.showsSelectionIndicator = YES;//loadFromPicker [caratFromPicker addSubview:caratTable]; 

and implemented UITableView delegates as:

 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [caratFromArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } tableView.separatorStyle = UITableViewCellSeparatorStyleNone; cell.textLabel.text = [caratFromArray objectAtIndex:indexPath.row]; return cell; } 

here is a screenshot of the same: enter image description here

but my problem is that I cannot scroll the table view to view the following values.

+5
source share
1 answer

You can try using the UIPicker delegate method:

 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)theView{ return YourTableView; } 

To set tableView as the view for the row.

0
source

Source: https://habr.com/ru/post/1233148/


All Articles