繁体   English   中英

如何实现“双重” UITextField?

[英]How can I implement a “double” UITextField?

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

替代文字
(来源: echofon.com

  1. 新文件(可可触摸类-> UIViewController子类)UITableViewController子类,带有XIB的接口(均选中)
  2. 打开Xib文件
  3. 更改属性检查器上的视图样式(普通->组)(苹果键+ 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.";
}

您需要将UITextField对象放置在表中以实现此效果。 有关更多详细信息,请参见UITableView: http : //developer.apple.com/iphone/library/DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM