さて、ここに問題があります。UIView内にUITableViewをロードしていますが、2つのテキストフィールドが表示されていません。
.h:
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {
UITableView *loginTableView;
UITextField *username;
UITextField *password;
}
@property UITableView *loginTableView;
@property UITextField *username;
@property UITextField *password;
@end
.m:
#import <QuartzCore/QuartzCore.h>
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
@synthesize loginTableView, username, password;
- (void)viewDidLoad {
[super viewDidLoad];
// Make rounded corners view
[self.view.layer setCornerRadius:4.0];
[self.view.layer setMasksToBounds:YES];
self.view.layer.opaque = NO;
self.view.backgroundColor = [UIColor whiteColor];
// Add login table view to main view
loginTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
loginTableView.delegate = self;
loginTableView.dataSource = self;
[self.view addSubview:loginTableView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
if( cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
if (indexPath.row == 0) {
username = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
username.placeholder = @"Username";
username.autocorrectionType = UITextAutocorrectionTypeNo;
[username setClearButtonMode:UITextFieldViewModeWhileEditing];
cell.accessoryView = username;
}
if (indexPath.row == 1) {
password = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
password.placeholder = @"Password";
password.secureTextEntry = YES;
password.autocorrectionType = UITextAutocorrectionTypeNo;
[password setClearButtonMode:UITextFieldViewModeWhileEditing];
cell.accessoryView = password;
}
username.delegate = self;
password.delegate = self;
[loginTableView addSubview:username];
[loginTableView addSubview:password];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
@end
誰かが私が間違っていることを教えてもらえますか?