English 中文(简体)
关于权宜之计,为什么主计长认为权宜行事?
原标题:On iOS, why the init in ViewController didn t work?
  • 时间:2012-04-21 03:57:35
  •  标签:
  • ios

在主计长的接口中,我已经过。

@property int count;

在执行过程中,我

@synthesize count;

-(id) init {
    self = [super init];
    if (self) {
        self.count = 100;
    }
    return self;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%i", self.count++);
}

但出于某种原因,第一次在<代码>上填写。 简讯

最佳回答

各种不同的方法之一,将视其是否来自轴心、故事板,或是在你的代码中手工操作。

实行这种初步化的一个更好的地点是:viewDid Load, 类似情况

- (void)viewDidLoad {
    [super viewDidLoad];
    self.count = 100;
}
问题回答

我怀疑你发现有点叫作。 如果你看一看《国际投资协议》,你就会看到其他初始化方法(例如,如果你重新使用《国际投资协议》,它将援引<<<<<<_tWithinexbNameun/Nameunbunbunbn>。 如果它通过一个故事板,它可能有所不同。 See the discussion of initialization in Rainbow s 方案规划指南》。

一般观点控制器配置的更好位置是viewDidLoad

修改如下:

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.count = 100;
    }
    return self;
}

这一观点实际上已经由第十一B所形成,后者正在对此加以脱节或将其box。 发生这种情况时,第十一章将<编码>initWithCoder:





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签