-1

私はこれを達成しようとしています:

ここに画像の説明を入力

しかし、私はこれを取得します:

ここに画像の説明を入力

ビューテーブルを備えたビューコントローラーがあります

これはインターフェースです:

@interface LoginViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tblCredentials;

@end

これは実装です:

@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

-(void)viewWillAppear:(BOOL)animated
{
    self.tblCredentials.delegate=self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    UITextField *textField = [[UITextField alloc] init];
    textField.enablesReturnKeyAutomatically = YES;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;

    CGRect cellBounds = cell.bounds;
    CGFloat textFieldBorder = 10.f;
    CGRect aRect = CGRectMake(textFieldBorder, 9.f, CGRectGetWidth(cellBounds)-(2*textFieldBorder), 31.f );

    textField.frame = aRect;

    if(indexPath.row==0)
    {
        textField.placeholder = @"Username";
        textField.returnKeyType = UIReturnKeyNext;
        textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    }
    else
    {
        textField.placeholder = @"Password";
        textField.returnKeyType = UIReturnKeyDone;
        textField.secureTextEntry = YES;
    }

    [cell.contentView addSubview:textField];

    return cell;
}


@end

cellForRowAtIndexPath にブレークポイントを配置しましたが、そこで停止しないため、これらのテキスト フィールドはレンダリングされません。

私は何が欠けていますか?

PS: これは目標を達成するための悪いアプローチですか? (これら 2 つのグループ化されたテキスト フィールド)

LE: xib ファイルのない stroyboard を使用しています

4

4 に答える 4

1

カスタム テーブル ビュー セルを作成する必要があります。このgithub リンクを見てください。

于 2013-08-04T07:56:39.453 に答える
0

テーブルビューのデリゲートを設定していますが、行数などのデータソースは設定していません。

また、デリゲートをサイクルの少し後半に設定しています。これは xib にあるため、デリゲートとデータソースをコードではなく xib に設定してみませんか? ビュー コントローラーがヘッダーのデリゲートおよびデータ ソース プロパティに準拠していることを宣言すると、IB で接続を行うことができます。コードで設定することを主張する場合は、viewDidLoad にある必要があります。

于 2013-08-04T07:49:53.723 に答える