I have two classes A and B.
Class A contains a UIView named myView and also a method MyMethod to set the position of the myView.
-(void)MyMethod:(NSString *)justCheck
{
[self.view addSubview:myView];
[self.view bringSubviewToFront:myView];
CGRect mframe = [myView frame];
NSLog(@"------------> MyMethod Called = %@",justCheck);
// EDIT: the following NSLogs are added later--------------------
NSLog(@"------------> MyMethod Called:mframe:x = %g",mframe.origin.x); //0
NSLog(@"------------> MyMethod Called:mframe:y = %g",mframe.origin.y); //42
NSLog(@"------------> MyMethod Called:mframe:H = %g",mframe.size.height); //317
NSLog(@"------------> MyMethod Called:mframe:W = %g",mframe.size.width); //320
//---------------------------------------------------------------
mframe.origin.y = 42;
[myView setFrame:mframe];
}
When a button in the class A named buttonOfA calls this MyMethod, it works perfectly and I can see the myView in position 42.
code is as below,
-(IBAction)buttonOfA:(id)sender
{
[self MyMethod:@"I am A"];
}
But, when the button of class B named buttonOfB tries to call this method, NSLog works but I cannot see the myView in position 42. Code as below,
-(IBAction)buttonOfB:(id)sender
{
[objOfA MyMethod:@"I am B"]; //objOfA is the object of class A
}
What is happening here??
I have been trying hard to figure out the problem, But I couldn’t. Plz help me.
Thanx 🙂
EDIT: four NSLogs are added in myMethod()
Make sure the
myViewinstance variable in the class A object is initialized and added to a super view when class B callsMyMethod:on it. Otherwise setting the frame won’t have any effect.