gpt4 book ai didi

ios - TableView 数据未显示在 iOS6 和 Xcode 的新 Storyboard场景中

转载 作者:行者123 更新时间:2023-11-29 11:04:52 24 4
gpt4 key购买 nike

我第一次尝试实现第二个场景,但遇到了一些问题。简单地尝试在 TableView 中显示一个单元格 block ,其中包含来自数组的数据。与我的第一个场景非常相似的代码,这就是为什么我对它为什么不起作用感到困惑。

代码如下:

#import "ChooseServerView.h"
#import "ViewController.h"

@interface ChooseServerView ()

@end

@implementation ChooseServerView;
@synthesize serverSelection;

- (void)viewDidLoad
{

serverSelection = [[NSArray alloc] initWithObjects:@"Chicgo, IL",@"London, UK",@"San Jose, CA",@"Washington, DC", nil];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


#pragma mark - Table View Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented
{
return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; // fixed font style. use custom view (UILabel) if you want something different

{
if (section == 0) {
return @"Standard Test Locations:";
}
else {
return @"Quality Test Locations:";
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
if (section == 0) {
return [serverSelection count];
}
else {
return 1;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

{

UITableViewCell *stdLocCell = nil;

stdLocCell = [tableView dequeueReusableCellWithIdentifier:@"serverSelection"];

if (stdLocCell == nil) {

stdLocCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"serverSelection"];

}

switch (indexPath.section) {
case 0:
stdLocCell.textLabel.text = [serverSelection objectAtIndex:indexPath.row];
break;
case 1:
stdLocCell.textLabel.text = @"Speed Test";
break;
default:
break;
}

return stdLocCell;

}

@end

segue 按预期工作,出现导航和标签栏,但没有单元格或数据,只是空白。

移动到新场景时,输出中有一条注释:

2013-01-03 13:08:34.878 MyConnection[15996:907] Unknown class GLKView in Interface Builder file.

不确定这是否与缺少数据有关。

New Class controller 连接到 Storyboard上的新场景,并出现在编译指令中,如下所示:

Compile Sources

Custom Class

最佳答案

您是否将委托(delegate)和数据源连接到 View Controller 。如果表格没有向您的 View Controller 寻求委托(delegate),您将得到一个空白的表格 View 。

关于ios - TableView 数据未显示在 iOS6 和 Xcode 的新 Storyboard场景中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14142356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com