将 UIPickerView 添加到 UITableViewCell [英] Adding UIPickerView to a UITableViewCell
问题描述
我想将 UIPickerView 添加到 UITableViewCell.现在我只是得到一个黑色的窗口.有人还可以向我解释将 UI 对象子类化为单元格的概念,即:我们什么时候将单元格作为委托和数据源委托?谢谢
I want to add a UIPickerView to a UITableViewCell. Right now I am just getting a black window. Can someone also explain me the concept of subclassing UI objects to a cell ie:when do we make our cell as the delegate and the datasource delegate? Thanks
这是我现在正在做的代码
Here is the code of what i am doing right now
case 1: {
cell = [tableView dequeueReusableCellWithIdentifier:@"groups"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"groups"];
}
/*NSString *myGroupDetail = [_groupArray objectAtIndex:indexPath.row];
NSLog(@"the group detail label is %@",myGroupDetail);
cell.textLabel.text = myGroupDetail;
*/
[cell addSubview:_groupPicker];
break;
}
组是我想要选择器视图的部分,我从数组中获取数据.
The groups is the section in which I want the picker view, I am getting that data from an array.
推荐答案
您必须在 tableviewdelegate 的 cellForRow 方法中分配和初始化一个选择器视图.我会为您绘制草图 =) 如果您稍微搜索一下,应该不难发现如何初始化单元格本身;-)
you would have to allocate and initialize a pickerview in your cellForRow method of the tableviewdelegate. ill sketch it for you =) how to initialize a cell itself should not be hard to find out if you google a bit ;-)
...(tableView *)... cellForRowAtIndexPath... {
if(indexPath.row == pickerRow){
UIPickerView *pickerView = [[UIPickerView alloc]init];
cell = ... // alloc and initialize a cell
cell addSubview:pickerView];
}
else{ // your other cells }
return cell;
}
更新:我目前在使用 git 时遇到问题,所以我上传了一个示例项目到我的私人服务器:UITablePicker 示例
UPDATE: im currently having trouble with git, so i uploaded a sample project to my private server: UITablePicker example
github:https://github.com/sebamisc/UItableViewWithPicker
你可以随意修改和使用代码=)
yu can modify and use the code however you want =)
塞巴斯蒂安
这篇关于将 UIPickerView 添加到 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!