Objective c UITableView是否使用UIPIckerView滚动到特定部分?

Objective c UITableView是否使用UIPIckerView滚动到特定部分?,objective-c,uitableview,uipickerview,Objective C,Uitableview,Uipickerview,我有一个UITableView,它有固定数量的节,但是每个节中的行数可能会根据服务器结果而变化 我想实现一个拾取轮来“跳”到每个部分。以下是我在UITableViewController中的UIPickerView委托方法: - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView

我有一个UITableView,它有固定数量的节,但是每个节中的行数可能会根据服务器结果而变化

我想实现一个拾取轮来“跳”到每个部分。以下是我在UITableViewController中的UIPickerView委托方法:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

return 1;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return 5;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [self.pickerArray objectAtIndex:row];
}
在ViewDidLoad中初始化的“pickerArray”:

self.pickerArray = [[NSArray alloc]initWithObjects:@"Watching", @"Completed", @"On Hold", @"Dropped", @"Planned", nil];
下面是我的didSelectRow方法:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
[self.tableView scrollToRowAtIndexPath:[self.pickerArray objectAtIndex:row] atScrollPosition:UITableViewScrollPositionNone  animated:YES];
}
我注意到没有“scrollTo*section*AtIndexPath”方法,这会很有帮助。苹果的文档中提到了“indexpath”参数:

indexPath
An index path that identifies a row in the table view by its row index and its section index.
调用该方法(在选择器中拾取内容)会引发以下错误:

*由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\u NSCFConstantString 节]:发送到实例0x4bdb8'的无法识别的选择器


知道我应该做什么吗?

ScrollToRowatineXpath方法将一个
NSIndexPath
作为第一个参数,但代码正在传递一个
NSString
导致异常

正如文档所说,
nsindepath
同时包含节和行(您必须知道这一点,因为您用节填充了表视图)

您需要创建一个
nsindepath
,它对应于表视图中与选择器视图中选定的
行相关的节的第一行

因此,假设选择器视图的
直接对应于表视图中的部分:

//"row" below is row selected in the picker view
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:row];

[self.tableView scrollToRowAtIndexPath:ip 
                      atScrollPosition:UITableViewScrollPositionNone 
                              animated:YES];

谢谢你的帮助。它工作得很好。我需要更仔细地阅读。