【发布时间】:2018-09-28 12:51:14
【问题描述】:
我有一个包含许多单元格的 UITableView。我可以多选单元格,但我想要的是用户只能按顺序选择多个单元格。即如果用户选择了第 2 行,那么他/她只能选择第 3 个单元格,然后依次选择第 4 个单元格,不允许选择随机单元格。
这是我所做的:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return arrPackages.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
PurchaseListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PurchaseListTableViewCell" forIndexPath:indexPath];
NSDictionary *dict = [arrPackages objectAtIndex:indexPath.row];
cell.lblPackageName.text = [dict valueForKey:@"package_name"];
cell.lblDiscount.text = [NSString stringWithFormat:@"You save: %@%%",[dict valueForKey:@"discount"]];
cell.lblLastAmount.text = [NSString stringWithFormat:@"%@",[dict valueForKey:@"package_price"]];
NSString *strPaymentStatus = [NSString stringWithFormat:@"%@",[dict valueForKey:@"payment_status"]];
if ([strPaymentStatus isEqualToString:@"2"]) {
cell.contentView.userInteractionEnabled = NO;
}
else{
cell.contentView.userInteractionEnabled = YES;
}
/*
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:@2
range:NSMakeRange(0, [attributeString length])];
*/
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// NSDictionary *dict = [_arrModuleData objectAtIndex:indexPath.row];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
【问题讨论】:
-
请展示您已经尝试过的内容、无效的内容、代码示例等。请阅读How to Ask 和minimal reproducible example 然后edit 您的问题显示最小值 演示问题的代码。
-
@AshleyMills 感谢您的回复。我在这里更新了代码。
标签: ios objective-c uitableview