【发布时间】:2015-01-06 06:37:19
【问题描述】:
我正在使用情节提要构建一个 iOS 应用。我已经用两个部分实现了UITableView,例如
Alpha
a
b >
Numb
1 >
2
3
我想在每个部分中选择单行并获取所选行的值。
我做不到,谁能帮帮我。
这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Uncheck the previous checked row
long sec = [indexPath section];
if(sec==0){
if(self->checkedIndexPath)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self->checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
if([self->checkedIndexPath isEqual:indexPath])
{
self->checkedIndexPath = nil;
}
else
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self->checkedIndexPath = indexPath;
}
}
else if(sec==1 ){
if(self->checkedIndexPath)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self->checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
if([self->checkedIndexPath isEqual:indexPath])
{
self->checkedIndexPath = nil;
}
}
}
【问题讨论】:
-
为您的 UITableView 实例设置多项选择 = ON。
标签: ios objective-c uitableview didselectrowatindexpath