0

ユーザーが任意の行を選択し、新しい行が挿入されたときに、セルにチェックマークのない画像がロードされたときに、テーブルビューセルのカスタムチェックマークとチェックマークを外した画像を表示したいと思います。

行を確認したら、新しいデータでテーブルをリロードした後でも、以前にチェックした行をそのまま表示し、新しい行を未チェックのまま表示したいと考えています。

最後にチェックマークが付いたすべての行を取得するにはどうすればよいですか。

試してみましたが、行の選択が解除されたときに変更できるカスタムチェックマーク画像を初めて読み込むことができませんが、上記のように一貫して機能しないため、いくつかの問題があります。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;

 }

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

   return [cardData.mArrRecipient count];

 }

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString * sCellIdentifier = @"cell";
    NSLog(@"cellforrow");


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
    if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sCellIdentifier] autorelease];

    RecipientData *recipientData = [[cardData.mArrRecipient objectAtIndex:indexPath.row]autorelease];
    cell.textLabel.text = recipientData.sRecipientFName;
} 
cell.accessoryType=UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
 {

    if (IndexPath) 
    {
        UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_checkmark_red.png"]] autorelease];
        [tableView cellForRowAtIndexPath:indexPath].accessoryView = imageView;
        IndexPath=FALSE;
    }
    else 
    {
        UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_uncheckmark_red.png"]] autorelease];
        [tableView cellForRowAtIndexPath:indexPath].accessoryView = imageView;
        IndexPath=TRUE; 
    }
  }


  -(void)viewWillAppear:(BOOL)animated
  {

[super viewWillAppear:animated];   
if ([cardData.mArrRecipient count]>0) 
{
    [IBTblNewRecipientDetail reloadData];        
}
 }

誰でもこれで私を助けることができますか??

4

2 に答える 2

1

チュートリアルはこちら http://weheartgames.com/2009/06/simple-iphone-checkbox/

またはこれを使用します

  UIButton   * checkBox=[UIButton buttonWithType:UIButtonTypeCustom];
        checkBox.tag=indexPath.row;
        checkBox.frame=CGRectMake(270,15, 20, 20);
        [cell.contentView addSubview:checkBox];
        [checkBox setImage:[UIImage imageNamed:@"selectedBoxWith.png"] forState:UIControlStateNormal];
        [checkBox addTarget:self action:@selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];

-(void)checkBoxClicked:(id)sender{
if(self.isChecked ==NO){
  self.isChecked =YES;
  [sender  setImage:[UIImage imageNamed: @"selectedBoxWithTik.png"] forState:UIControlStateNormal];
}else
{
   self.isChecked =NO;
  [sender setImage:[UIImage imageNamed:@"selectedBoxWith.png"]forState:UIControlStateNormal];

    }
}


and 

-(void)checkBoxClicked:(id)sender{

    UIButton *tappedButton = (UIButton*)sender;

    if([tappedButton.currentImage isEqual:[UIImage imageNamed:@"selectedBoxWith.png"]]) {
        [sender  setImage:[UIImage imageNamed: @"selectedBoxWithTik.png"] forState:UIControlStateNormal];
    }

    else {
        [sender setImage:[UIImage imageNamed:@"selectedBoxWith.png"]forState:UIControlStateNormal];
    }
}
于 2012-05-08T09:38:57.613 に答える