1

我是 iOS 新手。我正在使用故事板进行 UI 开发。我创建了一个带有标签和活动指示器的自定义标题单元格。我在我的表格视图中创建了两个部分。在第一部分有一行,在该行中,附件视图中有一个开关。现在我想要在我打开/关闭开关时执行活动指示器开始/停止动画。但是这在我的情况下没有发生。请帮我。

这是代码片段:

- (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