gpt4 book ai didi

ios - TableView 数据未显示

转载 作者:行者123 更新时间:2023-11-28 20:07:57 26 4
gpt4 key购买 nike

我制作了一个带有 2 个 View 的 View Controller 。在顶 View 中,我插入了一个 TableView ,其中包含静态单元格和一个基本单元格。当我运行该程序时,我手动输入到 tableview 的数据没有显示。

我的代码:

ViewController.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface CallTeacherViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *topLayer;

@property (nonatomic) CGFloat layerPosition;

查看 Controller .m

#import "CallTeacherViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface CallTeacherViewController ()

@end

@implementation CallTeacherViewController
@synthesize topLayer = _topLayer;
@synthesize layerPosition = _layerPosition;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...

return cell;
}

-(void)viewDidLoad {

self.topLayer.layer.shadowOffset = CGSizeMake(-1,0);
self.topLayer.layer.shadowOpacity = .9;
self.layerPosition = self.topLayer.frame.origin.x;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

#define VIEW_HIDDEN 80

-(void) animateLayerToPoint:(CGFloat)x
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
CGRect frame = self.topLayer.frame;
frame.origin.x = x;
self.topLayer.frame = frame;
}
completion:^(BOOL finished){
self.layerPosition =self.topLayer.frame.origin.x;
}];
}

- (IBAction)toggleLayer:(id)sender {
if (self.layerPosition == VIEW_HIDDEN) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint:VIEW_HIDDEN];
}
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

if (self.layerPosition == VIEW_HIDDEN) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint:0];
}
}

- (IBAction)panLayer:(UIPanGestureRecognizer*)pan {
if (pan.state == UIGestureRecognizerStateChanged) {
CGPoint point = [pan translationInView:self.topLayer];
CGRect frame = self.topLayer.frame;
frame.origin.x = self.layerPosition + point.x;
if (frame.origin.x < 0 ) frame.origin.x = 0;
self.topLayer.frame = frame;
}

if (pan.state == UIGestureRecognizerStateEnded) {
if (self.topLayer.frame.origin.x <= 81) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint: VIEW_HIDDEN];
}
}
}

最佳答案

这是用动态表格 View 内容填充您的表格 View 。如果您真的想要 Storyboard中的静态内容,请参阅 Ilario 的回答。

//小时

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *topLayer;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

//米

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// if you forget these two lines the methods below won't fire.
self.tableView.delegate = self;
self.tableView.dataSource = self;

self.items = @[@"Foo", @"Bar", @"Test"]; // whatever data you need
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

cell.textLabel.text = [self.items objectAtIndex:indexPath.row];

return cell;
}

关于ios - TableView 数据未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21381698/

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