I am trying to generate a UITextField in a view like this. I don't mind using IB or doing it programmatically.
A:
You need to place the UITextField objects inside of a table to achieve this effect. See UITableView for more details: http://developer.apple.com/iphone/library/DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html
Eric
2010-03-04 00:39:17
+4
A:
- New File(Cocoa Touch Class -> UIViewController subclass) UITableViewController subclass, With XIB for interface(check both)
- open Xib file
- change the view style(plain->group) on Attributes Inspector(apple key + 1)
- add following code in .m file
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 2; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if(indexPath.row == 0) { cell.textLabel.text = @"Username"; UITextField *field = [[[UITextField alloc] initWithFrame: CGRectMake(120, 10, 180, 30)] autorelease]; [cell addSubview:field]; } else if(indexPath.row == 1) { cell.textLabel.text = @"Password"; UITextField *field = [[[UITextField alloc] initWithFrame: CGRectMake(120, 10, 180, 30)] autorelease]; field.secureTextEntry = YES; [cell addSubview:field]; } return cell; }
- (NSString *)tableView: (UITableView *)tableView titleForHeaderInSection: (NSInteger)section { return @"Account"; }
- (NSString *)tableView: (UITableView *)tableView titleForFooterInSection: (NSInteger)section { return @"If you don't have a twitter account, go to twitter.com to sign up."; }
cappuccino
2010-03-04 00:57:59
Amazing! Thank you!
Cy.
2010-03-04 16:19:56