iPhone:UITableView,带有用于设置的自定义单元格

时间:2010-05-13 22:19:54

标签: iphone uitableview

我想在我的设置屏幕上使用UITableView。这样我的设置视图看起来就像苹果那样,使用组表视图,然后是UI元素,让您更改设置。

因此,似乎单元格不是从数组中加载的,但似乎每个单元都是自定义的。

关于如何做到这一点的想法?

2 个答案:

答案 0 :(得分:2)

对于初学者,请将tableViewStyle属性设置为UITableViewStyleGrouped。 然后更改数据源以提供具有所需组的2D数组,而不是简单数组。实际上,它非常简单。

您需要使用您想要的UIControl类型自定义行 - 我假设您已经这样做了。

编辑:

要将控件添加到行,请在创建单元格时创建它。

...
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0.0f, 5.0f, 30.0f, 30.0f)];

[button setTitle:@"Click Me!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
...

答案 1 :(得分:0)

你可以在没有数组的情况下完成。只需使用以下方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

然后可以使用switch-method来解析所有行和节。顶部方法标题上的那两行,你可以将它缩短一点。

NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];

不要忘记,手动的表格视图容易出错。

欢呼西蒙