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

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

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

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

        将按钮添加到 UITableViewCell

        时间:2023-07-07
          • <bdo id='dMgwW'></bdo><ul id='dMgwW'></ul>

          • <tfoot id='dMgwW'></tfoot>

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

                    <tbody id='dMgwW'></tbody>

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

                  本文介绍了将按钮添加到 UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 UITableViewCell 中添加一个按钮.这是我的代码:`

                  I want to add a button in a UITableViewCell. This is my code: `

                  if (indexPath.row==2) {
                      UIButton *scanQRCodeButton = [[UIButton alloc]init];
                  
                      scanQRCodeButton.frame = CGRectMake(0.0f, 5.0f, 320.0f, 44.0f);
                      scanQRCodeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                      scanQRCodeButton.backgroundColor = [UIColor redColor];
                      [scanQRCodeButton setTitle:@"Hello" forState:UIControlStateNormal];
                  
                      [cell addSubview:scanQRCodeButton];
                  }`
                  

                  现在,当我运行应用程序时,我只看到一个空白行!有什么想法吗?

                  Now, when I run the app, I see only a blank row ! Any ideas ?

                  推荐答案

                  虽然把它放在单元格的 contentView 中很自然,但我相当确定这不是问题(实际上,在过去,我已经从来没有在 contentView 中正确显示子视图,所以我一直使用单元格).

                  While it's natural to put it in the contentView of the cell, I'm fairly certain that is not the problem (actually, in the past, I've never had subviews displayed correctly in the contentView, so I've always used the cell).

                  无论如何,问题涉及您开始创建按钮时的前三行.前两行很好,但代码停止工作:

                  Anyway, the problem involves the first three lines of when you start creating your button. The first two lines are fine, but the code stops working with:

                  scanQRCodeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                  

                  buttonWithType: 实际上是一种方便的方法来创建一个按钮(它就像一个紧凑的alloc-init).因此,它实际上取消"了您过去的两行(您基本上创建了两次按钮).您只能将 init 或 buttonWithType: 用于同一个按钮,但不能同时使用.

                  buttonWithType: is actually a convenience method to create a button (it's like a compact alloc-init). Therefore, it actually "nullifies" your past two lines (you basically created the button twice). You can only use either init or buttonWithType: for the same button, but not both.

                  UIButton *scanQRCodeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                  scanQRCodeButton.frame = CGRectMake(0.0f, 5.0f, 320.0f, 44.0f);
                  scanQRCodeButton.backgroundColor = [UIColor redColor];
                  [scanQRCodeButton setTitle:@"Hello" forState:UIControlStateNormal];    
                  [cell addSubview:scanQRCodeButton];
                  

                  这将起作用(请注意,如果需要,您可以使用 cell.contentView).如果您没有使用自动引用计数 (ARC),我想提一下,您不必在内存管理方面做任何事情,因为 buttonWithType: 返回一个自动释放的按钮.

                  This will work (note that you can use cell.contentView if you wanted). In case you're not using Automatic Reference Counting (ARC), I would like to mention that you don't have to do anything in term of memory management, because buttonWithType: returns an autoreleased button.

                  这篇关于将按钮添加到 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用 ViewContainer 中的按钮隐藏视图容器 下一篇:带有 GradientLayer 的 UIButton 使图像模糊并使渐变变暗

                  相关文章

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

                  <tfoot id='sISFY'></tfoot>

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

                  2. <small id='sISFY'></small><noframes id='sISFY'>

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