0

さまざまなセクションと行を持つ uitaleviewcell があります。写真で確認できるチェックボックス セルが必要です。

私の質問は、uitableviewcells でチェックボックスを作成するにはどうすればよいですか? (私はストーリーボードを使用しました)

ここに画像の説明を入力

4

3 に答える 3

0

プロパティ インスペクタで と を使用UISwitchして、通常状態の空のボックス イメージとハイライト状態のチェック ボックス イメージを設定します。ただし、チェックボックスの動作は ios のスイッチで表されます。チェックボックスのヒット領域は非常に小さいため、特に提供した画像のように互いに接近している場合は、ユーザーにとって使いやすさの問題が生じる可能性があります。

UISwitch リファレンス

于 2012-08-08T08:22:11.657 に答える
0

セルの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;
}
于 2012-08-08T10:47:38.747 に答える
0

各チェックボックス セルはカスタムTableViewCell である必要があります。次に、ImageView と Label を TableViewCell にドロップし、didSelectRowAtIndex: を使用して、画像のチェック/チェック解除を切り替えます。

于 2012-08-08T08:34:59.963 に答える