如何实现"双"UITextField?

Cy.*_*Cy. 0 iphone cocoa-touch interface-builder

我试图在这样的视图中生成UITextField.我不介意使用IB或以编程方式进行.

alt text http://echofon.com/img/twitter/iphone/setup.png

Joe*_*oey 5

  1. 新文件(Cocoa Touch类 - > UIViewController子类)UITableViewController子类,带接口的XIB(检查两者)
  2. 打开Xib文件
  3. 更改Attributes Inspector上的视图样式(plain-> group)(apple key + 1)
  4. 在.m文件中添加以下代码
- (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.";
}