ios - Objective-C 创建 ViewController 的实例
<p><p>我想创建一个 ViewController 类的实例:</p>
<pre><code>ViewController *viewConnection = [init];
self.image.center = CGPointMake(self.image.center.x + 1, self.image.center.y);
if (CGRectIntersectsRect(self.image.frame, viewConnection.otherImage.frame)) {
;
}`
</code></pre>
<p>当类中的图像碰到 ViewController 中的图像时,它没有进入 if 语句,有人可以告诉我为什么吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试创建 ViewController 类的共享实例,如下所示:</p>
<pre><code>+ (id)sharedInstance {
static ClassName * sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [ init];
// Do stuff
});
return sharedInstance;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Objective-C 创建 ViewController 的实例,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22555576/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22555576/
</a>
</p>
页:
[1]