當我嘗試以編程方式創建11個文本字段時,我很掙扎。問題是文本字段不顯示。我在viewDidLoad
方法中創建它們。以編程方式創建UITextField時出現問題iphone
下面是我使用的代碼:
- (void)viewDidLoad
{
// Determine some basic info
int numberOfTextfields = 11;
int textfieldHeight = 40;
int textfieldWidth = 200;
// Create the UIScrollView
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, numberOfTextfields*textfieldHeight,textfieldWidth)];
// Create all the textfields
NSMutableArray *textfields = [NSMutableArray arrayWithCapacity:
(NSUInteger)numberOfTextfields];
for(int i = 0; i < numberOfTextfields; i++) {
UITextField *field = [[UITextField alloc] initWithFrame:
CGRectMake(0,i*textfieldHeight,textfieldHeight,textfieldWidth)];
[scrollView addSubview:field];
[textfields addObject:field];
}
[super viewDidLoad];
}
他們爲什麼不顯示任何線索?
在此先感謝。
你在哪裏把scrollview本身? – 2011-06-16 12:07:23