iphone - 使用 xcode 和 tablecells 登录表单

标签 iphone ios xcode uitableview

我知道有与此类似的问题,但由于我的方法不同,我将继续提问。我有一个 tableview Controller ,我打算将其用作我的应用程序的登录表单。它应该由两部分组成;第一部分有两个表格单元格;第一行是用户名文本字段,第二行是密码文本字段,第二部分只有一行作为登录按钮。我已经能够实现用户名和密码部分,但是由于第二行只有一行,所以实现起来有点困惑。这是我的代码示例;

- (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;

第二部分产生两行,本应只有一行,请帮忙谢谢。

最佳答案

函数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 总是返回 2,所以每个部分都有两行。您应该将逻辑放入函数中以获取所需的行数。

关于iphone - 使用 xcode 和 tablecells 登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14828313/

相关文章:

iphone - 在 iOS 中的 Orientation 上加载不同的 xib 文件

ios - 如何添加 UIViewController 作为在以编程方式创建的 UIView 中创建的 UIButton 操作的目标?

iphone - 如何检查是否设置了自定义委托(delegate)?

ios - 如何隐藏 Xcode 6 中的按钮?

ios - 从 UITableViewCell 内的 UITextField 中删除 Tap 手势

iphone - AppCode 上的当前位置模拟

ios - SwiftUI:将动态数据传递到内容 View 后重绘

ios - 在swift 4中使用codable解析嵌套数组

swift - 如何选择 nib 作为 Mac OS X 应用程序的启动界面

iphone - 在jQuery .click()的UIWebView App中检查Internet