- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有这个 XCTestCase 案例:
- (void)testAllInitializersConfigureTheView {
BIStationAnnotationView *withFrame = [[BIStationAnnotationView alloc] initWithFrame:CGRectNull];
XCTAssertTrue(CGRectEqualToRect(withFrame.frame, CGRectMake(0.f, 0.f, 30.f, 40.f)), @"Frame should be fixed");
}
测试 MKAnnotationView 的子类:
- (id)init {
if (self = [super init]) {
self.frame = _myFrame;
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
return self = [self init];
}
- (instancetype)initWithCoder:(NSCoder *)coder {
return self = [self init];
}
我得到了一个无限循环,因为 initWithFrame
调用了 init
而 init
调用了 initWithFrame
。
谁能解释一下为什么?
最佳答案
我猜 [UIView init]
正在调用 [self initWithFrame:CGRectZero]
,所以它正在调用您自己的 initWithFrame
方法,因为您有重载了它。
要解决你的问题,你应该简单地做同样的事情:)。init
应该调用 initWithFrame
而不是相反。
关于ios - 继承 MKAnnotationView 并从 initWithFrame : overloads 调用 init 时无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31613428/
我正在尝试使用不同类型的主题更新 UITableViewCell View 。 我有几个主题,但无法让它们正常工作。 @interface CustomRowBackground : UIView {
我正在尝试使用 UINavigationController,它利用 UINavigationBar 的自定义子类。但是,我遇到了 initWithFrame 的问题。当调用 initWithFram
这是我的 map 初始化代码: SKMapView *mapView = [[SKMapView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100, 10
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improv
我在我的 UIView 中声明了一个属性,如下所示: @property (nonatomic, strong) NSMutableArray *finishedLines; 我初始化使用: - (i
我注意到,为了以编程方式创建 UIToolbar,您需要设置其大小,例如使用 initWithFrame。有什么方法可以让它自动计算大小,以便在未来(过去?)版本的操作系统中,一切都将是正确的大小?我
你能帮我解决这个问题吗,因为方法 initWithFrame:reuseIdentifier 已被弃用: static NSString *CellIdentifier = @”Cell”; Cust
我试图重新创建一个 Xcode 项目,但我遇到了一个错误“'initWithFrame:reuseIdentifier' is deprecated”。这是代码: - (id)initWithFram
我想从已弃用的 initWithFrame:reuseIdentifier: 更新我的 TableView。 我的表格 View 使用自定义单元格。 到处都说要使用 initWithStyle:,并且
如果我在 iOS 中以编程方式实现自动布局,使用 initWithFrame 方法是否合适?如果不是如何初始化首选大小的 View ? 最佳答案 除非别无选择,否则最好避免使用 initWithFra
我有一个 UIView,其中添加了几个作为 subview 的按钮。目前我的按钮位于drawRect:中,我听说这是一个坏主意,因为drawRect可以被调用多次。我尝试将这些 UIButtons 移
我通过 Interfacebuilder 将 View Controller 设置为特定 View 。但 initWithFrame 没有调用,但是调用了 drawRect?当我放置断点时? 最佳答案
我有一个自定义 UIView 子类。在 IB 中,我指定了一个“占位符”UIView 并将该类设置为我的类名。我对 drawRect 方法的重写正在工作,并且背景着色正确,但 initWithFram
我创建了一个与 .xib 文件关联的 UIView 子类。此 UIView 子类将在 UIViewController 中使用。在 Controller 中,我认为我们如何实例化 UIView 子类有
我有一些 MyView 作为 UIView 的子类,具有以下方法: @interface MyView : UIView @property (nonatomic, strong) UIImage *
当单元格出队ReusableCellWithIdentifier时,自定义TableViewCell中不会调用awakeFromNib、initWithFrame、initWithCoder。请注意,
我正在尝试将 tableview 作为 subview 添加到我的 tableViewController,但我想在 storyboard 中设置单元格。这将是一个静态的 tableview。 这是在
我正在对 UIImageView 或 UIView 进行子类化,以生成带有数字的简单彩色图 block 。如果我正在使用 UIImageView,我会使用 initWithImage 方法。如果我使用
有人可以帮助我理解为什么我们在初始化之前首先调用 super 上的初始化方法。我在 UIView 的子类中遇到一段代码,想知道这里总是调用 myMethod,这意味着我没有在 UIView 中设置框架
我创建了一个 UIView 子类并且想在 initWithFrame: 上执行一个方法,但是这个方法没有被调用。 当我从正在执行的 initWithCoder: 调用方法时,代码崩溃并显示此错误: T
我是一名优秀的程序员,十分优秀!