1

私はiOSが初めてです。UI開発にストーリーボードを使用しています。ラベルとアクティビティ インジケーターを含むカスタム ヘッダー セルを作成しました。テーブル ビューに 2 つのセクションを作成しました。最初のセクションには 1 つの行があり、その行にはアクセサリ ビューのスイッチがあります。スイッチをオン/オフすると、アクティビティ インジケーターのアニメーションの開始/停止が必要になります。私の場合、これは起こっていません。私を助けてください。

コード スニペットは次のとおりです。

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

   UITableViewCell *cell=[tableView  dequeueReusableCellWithIdentifier:@"bluetoothCell"];
   UISwitch *addswitch=nil;


   if (addswitch==nil)
   {
      addswitch=[[UISwitch alloc]initWithFrame:(CGRectZero)];
   }

   if (indexPath.section==0)
   {
      if (indexPath.row==0)
      {
          cell.accessoryView=addswitch;
          [addswitch addTarget:self action:@selector(bluetoohSwitchClicked:) forControlEvents:UIControlEventValueChanged ];
          cell.textLabel.text=@"Bluetooth";
      }

   }
   else if (indexPath.section==1) {

          cell.textLabel.text=@"bluetooth devices";
          cell.accessoryView=nil;
   }


   return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   return 44.0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection: (NSInteger)section
{
    HeaderTableViewCell *customheader;
    NSLog(@"section.. %ld",(long)section);

    customheader=[ tableView  dequeueReusableCellWithIdentifier:@"headercell"];
    self.customheader=customheader;


    customheader.autoresizesSubviews=YES;

    if (section==0) {
      customheader.activityloader2.hidden=NO;
      customheader.tag=0;
      NSLog(@"section %ld,%@",(long)section,customheader);

     } 
     else if(section==1) {
       customheader.activityloader2.hidden=NO;
       customheader.tag=1;
       NSLog(@"sections %ld,%@",(long)section,customheader);
     }

    return customheader;
}

-(void)bluetoohSwitchClicked:(id) sender
{
     UISwitch* switchControl = sender;
     if ([switchControl isOn])
     {
        self.onoffswitch=@"ON";
        [switchControl setOn:YES animated:YES];


     }
     else
     {
       self.onoffswitch=@"OFF";
       [switchControl setOn:NO animated:YES];
     }

     [self bluetoothStatechanged:[self.onoffswitch isEqualToString:@"ON"]?       YES:NO];

}

-(void)bluetoothStatechanged:(BOOL)on
{

    HeaderTableViewCell* customheader=(HeaderTableViewCell *)[self  tableView:self.maintableview2 viewForHeaderInSection:1];

    __block CGRect frame=customheader.frame;

    if (on==YES) {
        [customheader.activityloader2 startAnimating];
        NSLog(@"yes block");
      }
   else
     {
        [customheader.activityloader2 stopAnimating];
        NSLog(@"No block");
     }
} 
4

0 に答える 0