2015-10-07 32 views
5

我在哪裏,我需要實現多類型選擇器中選擇一種問題擊中所以要爲此我這樣做:的UITableView內UIPickerView iOS中

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

並實現了UITableView的代表爲:

-(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; 
} 

這裏是相同的截圖: enter image description here

但我的問題是我不能夠在實現代碼如下滾動查看下一個值。

+2

之前的問題的答案你得到的是從某人編輯:) :) :) –

+0

haha​​hhahaha ..... Awesome agent chocks .... !!!那是真的 – user2998990

+0

你爲什麼要在選取器視圖內放置一個表視圖?這似乎非常不尋常。你能提供你想要實現的一些截圖嗎? –

回答

0

您可以嘗試使用UIPicker委託方法:

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

要設置的tableView作爲該行的看法。