开发者

initWith Frame?? CGRectMake - XIB Size is wrong

In my MainControllerClass I have a few XIB's that I am initializing and throwing on the screen - Here is an Example

self.widgetPeopleToBuyFor = [[WidgetAddPeopleToBuyFor alloc] initWithNibName:@"WidgetAddPeopleToBuyFor" bundle:nil andUser:self.currentUser];
self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
self.widgetPeopleToBuyFor.delegate = self;
[self.viewMainView addSubview:self.widgetPeopleToBuyFor.view];
[self.viewMainView bringSubviewToFront:self.widgetPeopleToBuyFor.view];

if ([self.currentUser.wPeopleToBuyForRect length] > 2) {
    NSLog(@"LOADING FROM DB");
    CGRect rect9 = CGRectFromString(self.currentUser.wPeopleToBuyForRect);
    self.widgetPeopleToBuyFor.view.frame = rect9;
}
else
{
    NSLog(@"FIRST TIME");
    self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
}

I'm building this app so the user can resize the the view to their desire, move it around etc. So when he user Exits I call this method to grab the view information.

- (NSString *) showInfoViewSize: (UIView *) view 
{
    return NSStringFromCGRect(view.frame);

}

So from there I save the informatio开发者_Python百科n in the Database, it saves ok - But I just learned the size doesn't matter - I could change it to (10,10,200,200) and the view stays the same exact size on the screen. So I know I threw a buch at you there. But in the End, the DB works fine - the IF statement gets fired off - Its just I can't resize the XIB on launch.

Should I be resizing it a different way? Should I keep track of the TRANSFORM from the pinch recoginier and just retransform it the scaleFactor at load? Seems kinda hokey to me.

Any help is appreciated - I've been beating myself up on this, and I bet its something super simple I'm missing.


view does not loads from xib until it is presented and hence at that time there will be no frame to set for view. let the view load first then set its frame afterwards.

change the view.frame in "viewWillAppear" in your controller's implementation.


Normally when something is just not working, it's because you've got a nil floating around somewhere you didn't expect. Remember, sending messages to nil is completely legal in ObjC (it just always returns nil).

So I'd step through this in the debugger and check everything to make sure it's a real instance and not nil.

But generally what you're doing (allocing a controller with a nib, setting that controller's view's frame, then adding the controller's view to a superview) is the correct way to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜