문제

I have a few line of code in viewwillappear method. I want to execute this code only once. How can i do this. However this code is inside a loop.

CALayer *myLayer = btn.layer; myLayer.borderColor = [UIColor blackColor].CGColor; myLayer.masksToBounds=NO; myLayer.borderWidth = 2.0; myLayer.shadowOffset = CGSizeMake(0, 3); myLayer.shadowRadius = 10.0; myLayer.shadowColor = [UIColor blackColor].CGColor; myLayer.shadowOpacity = 1.0;

도움이 되었습니까?

해결책

Declare a BOOL variable flag (or any name you like) in .h file. set it to NO in viewDidLoad method. In viewWillAppear method, have a check if this code is executed before:

for(---)
{
if(!flag)
 {
      //execute above lines of code
   flag = YES;
 }
}

just in last line, make its value YES.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top