I am new to iOS Development.
I have a navigation based application. In my application, I created dynamic buttons using for loop . I have two UITextField ( row and column ) in FirstViewController . When the user enters a row and column value, then click OK Button the row and column values . to anOtherViewController . In anOtherViewController I need to put the logic to create all buttons based on the values ββof rows and columns.
MyLogical Code:
for (int i = 1 ; i <= rows; i++) { for (int j = 1 ; j <= columns ; j++) { NSString *btnTitle = [NSString stringWithFormat:@"%d",buttonCount]; self.btnCount = [UIButton buttonWithType:UIButtonTypeRoundedRect]; self.btnCount.tag = [btnTitle intValue]; [self.btnCount setTitle: btnTitle forState: UIControlStateNormal]; [self.btnCount addTarget:self action:@selector(btnCountPressed:) forControlEvents:UIControlEventTouchUpInside]; self.btnCount.frame = CGRectMake(162+changedX, 60+changedY, 43, 43); [self.scrollView addSubview:self.btnCount]; [self.listOfbtnCount addObject:btnTitle]; changedY = changedY + 50; buttonCount = buttonCount + 1; } changedX = changedX + 55; if (i == rows) widthScView = changedX; if (heightScView == 0) heightScView = changedY; changedY = 5; }
My screen:

It works fine, but my problem is that if I enter the row and column values more than 40 (about), then my application needs more time to create a dynamic button. The problem is only related to the time required to create the button.
Is there a way to create a button faster? and I also need to know if my code is bad for memory management? please help me on these issues.
For information: I have no generated errors, I only have a question about the time-consuming process of creating buttons.
Thanks at Advance.
user1525369
source share