これと似たような質問があることは承知していますが、私のアプローチが異なるので、先に進んで質問します。アプリのログインフォームとして使用する予定のテーブルビューコントローラーがあります。2つのセクションで構成する必要があります。最初のセクションには2つのテーブルセルがあります。最初の行はユーザー名のテキストフィールドで、2番目の行はパスワードのテキストフィールドです。2番目のセクションには、サインインボタンとして機能する行が1つだけあります。ユーザー名とパスワードのセクションを作成することはできましたが、2行目には1行しかないため、実装が少し混乱します。これが私のコードのサンプルです。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (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];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if ([indexPath section] == 0)
{ // Email & Password Section
if ([indexPath row] == 0)
{ // Email
cell.textLabel.text = @"Username";
}
else
{
cell.textLabel.text = @"Password";
}
}
if ([indexPath section] == 1)
{
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = @"Sign In to App";
}
return cell;
}
2番目のセクションでは、2つの行が生成されますが、1つだけである必要があります。ありがとうございます。