繁体   English   中英

以编程方式填充的UITableView无法填满屏幕

[英]Programmatically populated UITableView can't fill the screen

我正在学习本教程: http : //www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/ ,它显示了如何创建UITableView并以编程方式填充它。 很好,它有效。

现在,我试图使表格填满屏幕:无论设备或方向如何。 我这样做:

在此处输入图片说明

但是现在表格视图根本没有出现在我的屏幕上(我想由于约束问题,它就在很远的地方了吗?)。

我真的没有太多要显示的代码。 我实际上只是将UITableView放入界面构建器中,然后按照该教程将委托设置为我的视图控制器。 该方法将是

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}

其中tableData是具有16个字符串的数组。

尝试删除所有约束,然后选择tableView并再次添加它们,然后按添加4个约束 请确保您没有歧义。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM