我正在开发一个包含两个部分的动态表格视图:-注册签名-拒绝签名
我所有的值都在每个部分取决于字典中的标志:
[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"]
如果为0则表示未注册签名,否则表示已注册
但我不确定如何在我的方法中开发打印部分
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
这是我的发展:
#pragma mark *** Common methods: Tableview delegate methods ***
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if (section == 0) return @"not registered signatures";
return @"Registered signatures";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
if ([self.userSignatures count] > 0){
int firmasRegistradas = 0;
for (int i = 0; i < [self.userSignatures count]; i++) {
if (![[[self.userSignatures objectAtIndex:i] valueForKey:@"idFirma"] isEqualToString:@"0"])
firmasRegistradas += 1;
}
if (section == 0) return [self.userSignatures count] - firmasRegistradas;
if (section == 1) return firmasRegistradas;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
UILabel *EntidadFirmante = (UILabel *) [cell viewWithTag:2];
UILabel *statusFirma = (UILabel *) [cell viewWithTag:3];
if ([self.userSignatures count] > 0) {
EntidadFirmante.text = [[self.userSignatures objectAtIndex:indexPath.row]objectForKey:@"titFirmante"];
statusFirma.text = [[self.userSignatures objectAtIndex:indexPath.row]objectForKey:@"idDoc"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSLog(@"idFirma: %@",[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"]);
if (indexPath.section == 0 && [[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"] isEqualToString:@"0"]) return cell;
else
if (indexPath.section == 1 && ![[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"] isEqualToString:@"0"]) return cell;
}
else{
EntidadFirmante.text = @"There's no signatures";
statusFirma.text = @"without signatures";
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
关键在这里:
if (indexPath.section == 0 && [[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"] isEqualToString:@"0"]) return cell;
else
if (indexPath.section == 1 && ![[[self.userSignatures objectAtIndex:indexPath.row] objectForKey:@"idFirma"] isEqualToString:@"0"]) return cell;
如果我有这样的清单
- 挂号的
- 挂号的
- 未注册
- 挂号的
我期待这样的事情:
注册签名:1. 2. 4.
3.未注册的签名
但到目前为止我得到了这样的东西
注册签名:1. 2. 4.
未注册签名 1.(已注册)
如果未注册的签名是第三个,它会打印但第一个(已注册)
任何帮助我都会感激