我对 XCode 非常陌生,我正在尝试将数据填充到一个表视图中,该表视图是视图控制器的子视图。但我不断收到运行时错误,我不知道为什么。请帮忙。
我做的第一件事是在情节提要中创建视图,调整其大小,然后将其保留为动态原型表。
然后我控制单击将表格拖到我的 View Controller 类上,并且正如预期的那样,它创建了一个属性:
@interface FAViewController () <UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *myTable;
@end
请注意,我添加了 UITableViewDataSource 协议。然后我将这个类声明为数据源:
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTable.dataSource= self;
}
最后,我实现了所需的必需方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if ([tableView isEqual:self.myTable]) {
return 1;
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = @"Test";
return cell;
}
当我运行该应用程序时,它会将我带到这段代码:
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([FAAppDelegate class]));
}
}
并说信号 SIGBART。我希望我已经提供了所有相关信息。如果没有,请告诉我。