2013年3月31日星期日

Auto Layout Demo code

UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [button setTitle:@"action" forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    NSLayoutConstraint *btnCon=[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:[button superview] attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-20.0];
    
    NSLayoutConstraint *btnCon2=[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:[button superview] attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-20.0];
    [self.view addConstraint:btnCon2];
    [self.view addConstraint:btnCon];

2013年3月19日星期二

Facebook iOS position interview question

   last week Facebook recruit found me in LinkedIn, so he ask me if you would be interested in iOS opportunities within Facebook. I currently live in Shanghai,China, if have a chance go to bay area wok is biggest change in my life.  So I accept his request.
   next is recruiter test question :

 Question 1: When running out of memory, how does the system give your app one last chance to prevent being killed?
a) Autorelease
b) Jetsam
c) Memory Warning
d) UIApplicationWillTerminateNotification
 Question 2: What is the difference between a UIView's 'frame' and its 'bounds'
a) 'frame' defines the view's position and size; 'bounds' defines its clipping rect
b) 'frame' defines the view's clipping rect; 'bounds' defines its position and size
c) 'frame' defines position and size in the coordinate space of its superview; 'bounds' defines position and size in the coordinate space of the view itself
d) They are equal
 Question 3: The delegation pattern is often used to:
a) Report value changes from a Model to a Controller
b) Communicate messages back from one object to its owning object
c) Broadcast messages from a singleton object (e.g. NS User Defaults) to its listener
d) All of the above
Question 4: Which of the following cannot be retained:
a) NSString literal
b) NSNull
c) NSInteger
d) NSNotification
 Question 5: A block cannot:
a) Be subclassed
b) Be retained or released
c) Access 'self' from the scope in which it is declared
d) Be passed as an argument
another question : what does KVO stand for?

   yesterday Facebook Engineer give me a Skype interview:




@interface UIControl: UIView
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
@end
@implementation UIControl
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
  // How would you implement this?
}
// A UIControlEventTouchUpInside just happened. Let every interested target know…
- (void)_fireTargetsAndActionsForEvent:(UIControlEvents)controlEvent
{
  // ???
}
 
[myButton addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];


  others question:
how runloop work and autorelease object?
will lead to myButton retain target self?
_fireTargetsAndActionsForEvent complexity?

Today morning, I receive recruiter mail, he told I don't get  chance to next round interview.
I'm very sad, maybe there have many candidates who are best than me.  So I don't have chance work for the company, the interview experience is good for me.