さまざまなセクションと行を持つ uitaleviewcell があります。写真で確認できるチェックボックス セルが必要です。
私の質問は、uitableviewcells でチェックボックスを作成するにはどうすればよいですか? (私はストーリーボードを使用しました)
さまざまなセクションと行を持つ uitaleviewcell があります。写真で確認できるチェックボックス セルが必要です。
私の質問は、uitableviewcells でチェックボックスを作成するにはどうすればよいですか? (私はストーリーボードを使用しました)
プロパティ インスペクタで と を使用UISwitch
して、通常状態の空のボックス イメージとハイライト状態のチェック ボックス イメージを設定します。ただし、チェックボックスの動作は ios のスイッチで表されます。チェックボックスのヒット領域は非常に小さいため、特に提供した画像のように互いに接近している場合は、ユーザーにとって使いやすさの問題が生じる可能性があります。
セルのimageViewには2つの画像が必要です
#define SELECTED_ROW @"selectedRowImage.png" // CheckBox with Selected sign png
#define NOT_SELECTED_ROW @"notSelectedRowImage.png" // Empty CheckBox png
// listSelected is array of indexes selected
in ViewDidLoad:
NSMutableArray *listSelected = [[NSMutableArray alloc]init];
// CellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"select";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if ([self checkIfIndexPathAlreadySelected:indexPath])
cell.tag = 1;
else cell.tag = 0;
if(cell.tag == 0)
cell.imageView.image = [UIImage imageNamed:NOT_SELECTED_ROW];
else
cell.imageView.image = [UIImage imageNamed:SELECTED_ROW];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell.tag == 0)
{
cell.tag = 1;
[self.listSelected addObject:indexPath]];
cell.imageView.image = [UIImage imageNamed:SELECTED_ROW];
}
else if(cell.tag == 1)
{
cell.tag = 0;
[self.medicineIndexArray removeObject:indexPath];
cell.imageView.image = [UIImage imageNamed:NOT_SELECTED_ROW];
}
}
- (BOOL)checkIfIndexPathAlreadySelected:(NSIndexPath *)indexPath
{
if([self.listSelected containsObject:indexPath])
return YES;
else
return NO;
}
各チェックボックス セルはカスタムTableViewCell である必要があります。次に、ImageView と Label を TableViewCell にドロップし、didSelectRowAtIndex: を使用して、画像のチェック/チェック解除を切り替えます。