简体   繁体   English

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

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

I am following this tutorial: http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/ which shows how to create an UITableView and populate it programmatically. 我正在学习本教程: http : //www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/ ,它显示了如何创建UITableView并以编程方式填充它。 All's good, it works. 很好,它有效。

Now, I am trying to make the table fill the screen: regardless of the device or orientation. 现在,我试图使表格填满屏幕:无论设备或方向如何。 I did this: 我这样做:

在此处输入图片说明

But now the table view simply does not appear in my screen (I imagine it is somewhere far away due to a problem with the constraints?). 但是现在表格视图根本没有出现在我的屏幕上(我想由于约束问题,它就在很远的地方了吗?)。

There really isn't much code for me to show. 我真的没有太多要显示的代码。 I literally just placed an UITableView into the interface builder, and followed that tutorial to set the delegate to my view controller. 我实际上只是将UITableView放入界面构建器中,然后按照该教程将委托设置为我的视图控制器。 The methods would be 该方法将是

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

Where tableData is an array with 16 strings. 其中tableData是具有16个字符串的数组。

Try to remove all constraints, then select your tableView and add their again and press Add 4 constraints . 尝试删除所有约束,然后选择tableView并再次添加它们,然后按添加4个约束 Be sure, you don't have some ambiguity. 请确保您没有歧义。

在此处输入图片说明

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

相关问题 无法以编程方式从UITableView中删除行 - Can't programmatically delete row from UITableView 无法使用带有约束的UITableView填充屏幕 - Cannot fill the screen with UITableView with constraints UITextView无法在以编程方式创建的UITableView中关闭键盘 - UITextView can't dismiss the keyboard in programmatically-created UITableView UITableView 不会在 iPad 上填满整个屏幕 - UITableView does not fill out entire screen on iPad UITableView(Cell)不会填满整个屏幕 - UITableView(Cell) does not fill up entire screen 为什么我的UITableView不能变长并在屏幕上调整大小? - Why my UITableView can't become longer, and resizing on the screen? 如何使用Interface Builder扩展UITableView以在iPhone 5上填充全屏? - How can I expand UITableView to fill full screen on iPhone 5 using Interface Builder? 如何拖放可以自动展开以填充Xcode 8.2.1全屏的UITableView - How to drag and drop a UITableView that can automatically expand to fill the full screen in Xcode 8.2.1 旋转时无法获得背景渐变以填满整个屏幕 - Can't get background gradient to fill entire screen upon rotation 以编程方式移除 UITableView 的头部并自动调整内容大小以填充移除区域 - Programmatically remove the header of UITableView and automatically resizes the content to fill in the removed area
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM