Я пытаюсь добиться этого:cellForRowAtIndexPath не срабатывает. Что мне не хватает?
но я получаю это:
У меня есть вид cotroller с таблицей просмотра на нем
Это Интерфейс:
@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: Это плохой подход к достижению цели? (эти два сгруппированных текстовых полей)
LE: Я использую stroyboard, без XIb файлов
набор TableView делегат от XIB или позвоните '[self.tblCredentials reloadData]' после установки делегата в 'viewWillAppear' – samfisher
было бы лучше, чтобы установить вид таблицы и DataSource делегатов гораздо раньше, например, в' -ViewDidLoad'. – holex
В viewWillAppear Я установил делегат и перезагрузил данные tblCredentials, но без результата; – user2611691