- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 tableviewcell 中有按钮。[cell addSubview:button]
和 [cell.contentview addsubview:button]
有什么区别?因为当我在 tableview 中使用 [cell addSubview:button]
时,按钮功能工作正常但我在 table view 中的界面搞砸了,在我 ScrollView 并返回 tableview 后按钮转到左侧单元格。另一方面,当我使用 [cell.contentview addsubview:button]
按钮功能不起作用并且没有任何内容保存到 myarray。
按钮代码:
UIButton *button=(UIButton *) [cell viewWithTag:103];//fav
[button setImage:[UIImage imageNamed:@"unfav.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"fav.png"] forState:UIControlStateSelected];
button.frame = CGRectMake(0,0, 50, 50);
button.tag = indexPath.row;
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button]; // add the button to the cell
[cell bringSubviewToFront:button];
最佳答案
contentView
是单元格的默认 View ,其中添加了所有 subviews
。cell.view 是主视图,其中 contentView
本身被添加并且 cell.contentView
覆盖了 cell.view 的整个区域。但是在您将按钮添加到 cell.view 的情况下。
来自关于 ContentView
的苹果文档,
The content view of a
UITableViewCell
object is the defaultSuperView
for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
关于ios - [cell addSubview :button] and [cell. contentview addsubview:button] 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34249018/
我已经用 swift 编写了一堆代码并且更喜欢以编程方式编写很多代码,我想知道这两者之间的区别是什么: self.view.addSubview(someNewView) view.addSubvie
我在 tableviewcell 中有按钮。[cell addSubview:button] 和 [cell.contentview addsubview:button] 有什么区别?因为当我在 ta
我知道Apple建议开发者在self.contentview中添加 subview ,但是如果我们在UITableViewCell中添加 subview 会发生什么? 最佳答案 ios 7以后[s
我需要在 viewcontroller 的顶部显示 loaderView let loaderView: UIView() self.view.window?.addSubview(loaderVie
// Create and add a sub view CGRect viewRect = CGRectMake(0, 0, 200, 200); UIView *a_sub_view = [[UI
如何将 View 添加到窗口,以便调整 View 大小以适合窗口框架? 问题 我正在制作一个包含 2 个 View 的工作表窗口,其中一次只能看到其中一个 View ,因此 View 与窗口的大小相同
当我使用 addSubview方法,然后 removeFromSubview加载下一个 ViewController 然后加载 View 几次后,我的应用程序崩溃。我有很多关于 View 的图像。 尽
我试图让我的标 checkout 现动画: - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { if (isS
我有两个 UIView,名为 A 和 B,我将 UIView B 添加到 A 的 subview 中: [A.view addSubview B] 我想知道是否有任何委托(delegate)或 Hoo
我有类似的东西: (1) NavigationController --> (2) UITableViewController --> (3 afted clicked in a cell) UIVi
我有动画打开 NSViewController,它尝试添加 subview : [self.view addSubview:joinToCompanyView]; joinToCompanyView.
在使用 addSubview 时防止内存泄漏的正确方法是什么?我收到来自 Instruments 的投诉,说这段代码存在漏洞。我做错了什么? 示例代码: 我的.h @interface MyCusto
以下代码的结果是:我没有看到标签。 我的理解是标签的 intrinsicSize 会允许标签拉伸(stretch)。为什么没有发生这种情况? import UIKit class ViewContro
错误 -> “UIVIew”没有名为“addSubView”的成员 override func viewDidLoad() { super.viewDidLoad() // Do an
在使用 addSubview() 加载 View Controller View 时,我遇到了一个奇怪的行为: 硬件和软件:OSX 10.9.5 Mavericks、XCode 6 Beta 6 上的
使用 addSubview 方法向 UIAlertView 添加一些控件在 iOS7 中已弃用。据我所知,Apple promise 添加 contentView 属性。 iOS 7 现在发布了,我看
我有一个已加载到 MainWindow.xib 中的 View 。它只是一个带有 uiimageview 的 View ,在整个屏幕(320 X 480)上显示图像。当应用程序加载时,我显示此 Vie
我有一个基于 UITabBar 的应用程序,它运行得很好。在某些情况下,我会显示不同的 UIViewController。现在让我烦恼的是,我必须调整测试 Nib 的框架(并且仅测试 Nib !)才能
嗨,我正在 xcode 3.2.3 中编写一个应用程序。我想要做的就是切换到另一个 View ,但我不确定这样做的最佳方法。我可以通过这两种方式中的任何一种... PreferencesViewCon
我遇到了一个奇怪的问题..我想向我当前的 View 添加一个 UIViewcontroller(称为 iView)。我通过调用 iView = [[KFKaraokeInfosView allo
我是一名优秀的程序员,十分优秀!