1

私はiPhone開発者の初心者ですが、

私のアプリケーションでは、ボタンをクリックするとポップオーバーが表示されます。

私がやりたいことは、ポップオーバーで任意の行を選択すると、そのセルは次のような右矢印の画像でマークされるべきです:

cell.accessoryType = UITableViewCellAccessoryCheckmark;

その選択した行のテキストを取得したい。

要するに、ポップオーバーにチェックボックスを実装したいのですが、5行が選択されている場合、その5行のテキストをフェッチして配列に保存したいのです。

これが私のコードです:

-(void)btnClicked{
    UIViewController* popoverContent = [[UIViewController alloc]init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(110, 0, 500, 4)];

    UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 250, 665) style:UITableViewStylePlain];

    [table setDelegate:(id<UITableViewDelegate>)self]; 
    [table setDataSource:(id<UITableViewDataSource>)self]; 
     [self.view addSubview:table];
    [table release];

    [popoverView addSubview:table];
    popoverContent.view = popoverView;
    popoverContent.contentSizeForViewInPopover = CGSizeMake(250, 600);
    self.popoverController = [[UIPopoverController alloc]
                              initWithContentViewController:popoverContent];

    [self.popoverController  presentPopoverFromRect:CGRectMake(100,0, 535, 35) 
                                             inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];


    [popoverView release];
    [popoverContent release];
} 

この後、配列を UITableView に渡します。

前もって感謝します !

4

2 に答える 2

1

didSelectedRow メソッドに以下のコードを実装してください。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
  {
       NSMutableArray *cells = [[NSMutableArray alloc] init];
       for(int index=0;index<indexPath.row;index++)
       {
           UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
           [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
           [cells addObject:cell.textLabel.text];
       }
  }
于 2012-06-21T08:58:58.080 に答える
0

以前のコードを編集した新しいコードを見つけてください。

  if(cells == nil)
       cells = [[NSMutableArray alloc] init];

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath]
{
   if(indexPath.row < cells.count)
   {
      NSMutableDictionary *dict = [cells objectAtIndex:indexPath.row];
      BOOL isChecked = [[dict objectForKey:"isChecked"] boolValue];

      if(!isChecked)
      {
         [cells removeAllObjects];
         for(int index=0;index<indexPath.row;index++)
         {
             UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
             [cell setAccessoryType:UITableViewCellAccessoryCheckmark];

             dict = [[NSMUtableDictionary alloc] init]
             [dict setObject:@"true" forKey:@"isChecked"];
             [dict setObject:cell.textLabel.text forKey:@"rowText"];
             [cells addObject:dict];
             [dict release];
         }
      }
      else
      {
         UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
         [cell setAccessoryType:UITableViewCellAccessoryNone];
         [cells removeObjectAtIndex:indexPath.row];
      }
   }
   else
   {
         [cells removeAllObjects];
         for(int index=0;index<indexPath.row;index++)
         {
             UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
             [cell setAccessoryType:UITableViewCellAccessoryCheckmark];

             dict = [[NSMUtableDictionary alloc] init]
             [dict setObject:@"true" forKey:@"isChecked"];
             [dict setObject:cell.textLabel.text forKey:@"rowText"];
             [cells addObject:dict];
             [dict release];
         }
   }

}

配列はグローバルである必要があることに注意してください

于 2012-06-21T12:32:52.270 に答える