• <tfoot id='AS2Sf'></tfoot>
  • <legend id='AS2Sf'><style id='AS2Sf'><dir id='AS2Sf'><q id='AS2Sf'></q></dir></style></legend>

  • <small id='AS2Sf'></small><noframes id='AS2Sf'>

      <bdo id='AS2Sf'></bdo><ul id='AS2Sf'></ul>

    <i id='AS2Sf'><tr id='AS2Sf'><dt id='AS2Sf'><q id='AS2Sf'><span id='AS2Sf'><b id='AS2Sf'><form id='AS2Sf'><ins id='AS2Sf'></ins><ul id='AS2Sf'></ul><sub id='AS2Sf'></sub></form><legend id='AS2Sf'></legend><bdo id='AS2Sf'><pre id='AS2Sf'><center id='AS2Sf'></center></pre></bdo></b><th id='AS2Sf'></th></span></q></dt></tr></i><div id='AS2Sf'><tfoot id='AS2Sf'></tfoot><dl id='AS2Sf'><fieldset id='AS2Sf'></fieldset></dl></div>

      1. 用户单击完成按钮后如何更改 UIButton 的图像是 iOS 中的另一个 UIView

        How to change image for UIButton after user click on Done button is another UIView in iOS(用户单击完成按钮后如何更改 UIButton 的图像是 iOS 中的另一个 UIView)

        <i id='XIVME'><tr id='XIVME'><dt id='XIVME'><q id='XIVME'><span id='XIVME'><b id='XIVME'><form id='XIVME'><ins id='XIVME'></ins><ul id='XIVME'></ul><sub id='XIVME'></sub></form><legend id='XIVME'></legend><bdo id='XIVME'><pre id='XIVME'><center id='XIVME'></center></pre></bdo></b><th id='XIVME'></th></span></q></dt></tr></i><div id='XIVME'><tfoot id='XIVME'></tfoot><dl id='XIVME'><fieldset id='XIVME'></fieldset></dl></div>
          <tbody id='XIVME'></tbody>
      2. <tfoot id='XIVME'></tfoot>

        1. <legend id='XIVME'><style id='XIVME'><dir id='XIVME'><q id='XIVME'></q></dir></style></legend>

            • <small id='XIVME'></small><noframes id='XIVME'>

                • <bdo id='XIVME'></bdo><ul id='XIVME'></ul>

                  本文介绍了用户单击完成按钮后如何更改 UIButton 的图像是 iOS 中的另一个 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当用户单击 tableview 上的 UIButton 时(tableview 在每一行中都有多个按钮),会显示另一个视图.在用户单击另一个 UIView 的完成按钮后,我想更改此按钮的图像.我怎样才能做到这一点?我是新手.你能为我提供一些代码吗?提前致谢.

                  When the user clicks on a UIButton on tableview ( tableview has mutiple button in each row), another View is shown. I want to change image for this button after the user has clicked on the Done button of the other UIView. How can I do that? I'm a newbie. Could you please provide some code for me? Thanks in advance.

                  更新代码:

                  表格视图代码:

                      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
                  {
                      NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];
                  
                      UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                      if (cell == nil)
                      {
                          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                  
                          UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
                          [market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];
                  
                          [market setTag:3000];
                          [market setFrame:CGRectMake(200, 6, 30, 30)];
                          [cell.contentView addSubview:market];
                  
                      }
                  
                     for (UIButton *button in [cell subviews]) { // change name of table here
                      if ([button isKindOfClass:[UIButton class]]) {
                          button.tag = indexPath.row;
                          [button setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateNormal];
                      }
                  }
                  
                  
                      cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
                      _tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
                  
                      return cell;
                  }
                  

                  打开按钮的代码(用户单击以显示另一个视图的按钮)

                  Code for Open button ( button that user click on to show another View)

                      - (void)marketPressedAction:(id)sender
                  {
                  
                      UIButton *button = (UIButton *)sender;
                      buttontag = button.tag;
                      NSLog(@"Market button click at row %d",buttontag);
                  }
                  

                  完成按钮的代码:

                   -(void)submitMarket
                  {
                      for (UIButton *button in [_tableView subviews]) { // change name of table here
                          if ([button isKindOfClass:[UIButton class]]) {
                              if (button.tag == buttontag) {
                                  [button setBackgroundImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateNormal];
                              } 
                          } 
                      }
                  }
                  

                  推荐答案

                  试试这个:

                  [yourButton setBackgroundImage:someImge forState:UIControlStateNormal];
                  

                  按钮点击代码:

                   savedTag = button.tag;
                  

                  完成按钮点击代码:

                  for (UIButton *button in [table subviews]) { // change name of table here 
                    if ([button isKindOfClass:[UIButton class]]) { 
                      if (button.tag == savedtag) { 
                         [button setBackgroundImage:someImge forState:UIControlStateNormal];
                      } 
                    } 
                  }
                  

                  在 cellForRowAtIndexPath 中代替这个:[market setTag:3000];[market setTag:indexPath.row];

                  In cellForRowAtIndexPath in place of this : [market setTag:3000]; write [market setTag:indexPath.row];

                  试试这个:

                  替换:

                  marketButton = (UIButton *)[cell.contentView viewWithTag:3000];
                  [marketButton setTag:indexPath.row];
                  

                  有了这个:

                  for (UIButton *button in [cell subviews]) { // change name of table here
                       if ([button isKindOfClass:[UIButton class]]) {
                           button.tag == indexPath.row; 
                       }
                  }
                  

                  还有一件事:将 cellForRowAtIndexPath 的第一行设为:

                  One more thing : make first line of cellForRowAtIndexPath as :

                  NSString *CellIdentifier = @"tableCell";

                  将你的 cellForRowAtIndexPath 更改为:

                  Change your cellForRowAtIndexPath as :

                  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
                  {
                      NSString *CellIdentifier = @"cell";
                  
                      UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                      if (cell == nil)
                      {
                          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                  
                          UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
                          [market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];
                  
                          [market setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateNormal];
                  
                          [market setTag:indexPath.row];
                          [market setFrame:CGRectMake(200, 6, 30, 30)];
                          [cell.contentView addSubview:market];
                  
                      }
                  
                      else {
                  
                         for (UIButton *button in [cell subviews]) { // change name of table here
                           if ([button isKindOfClass:[UIButton class]]) {
                              button.tag = indexPath.row;
                           }
                      }
                  }
                  
                  
                      cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
                      _tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
                  
                      return cell;
                  }
                  

                  这篇关于用户单击完成按钮后如何更改 UIButton 的图像是 iOS 中的另一个 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UIButton title text color(UIButton 标题文本颜色)
                  Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                  Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                  How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  UIButton remove all target-actions(UIButton 删除所有目标动作)
                      <tbody id='hxRIf'></tbody>

                      • <legend id='hxRIf'><style id='hxRIf'><dir id='hxRIf'><q id='hxRIf'></q></dir></style></legend>

                          <tfoot id='hxRIf'></tfoot>
                            <bdo id='hxRIf'></bdo><ul id='hxRIf'></ul>
                          • <i id='hxRIf'><tr id='hxRIf'><dt id='hxRIf'><q id='hxRIf'><span id='hxRIf'><b id='hxRIf'><form id='hxRIf'><ins id='hxRIf'></ins><ul id='hxRIf'></ul><sub id='hxRIf'></sub></form><legend id='hxRIf'></legend><bdo id='hxRIf'><pre id='hxRIf'><center id='hxRIf'></center></pre></bdo></b><th id='hxRIf'></th></span></q></dt></tr></i><div id='hxRIf'><tfoot id='hxRIf'></tfoot><dl id='hxRIf'><fieldset id='hxRIf'></fieldset></dl></div>

                            <small id='hxRIf'></small><noframes id='hxRIf'>