问题描述
我正在编写一个app hat有很多视图,我使用了滑动视图库( ECSlidingViews
)。问题是当我用一个对象填充数组并用 tableView:cellForRowIndexPath:
方法中的对象填充表时,它确实在表中显示数据,但是当我去到其他视图并返回数据消失,因为 tableView:cellForRowIndexPath:
未被调用。下面是代码:
I'm writing an app hat has many views and I used sliding views library (ECSlidingViews
). The problem is when I fill an array with objects and fill the table with the objects in tableView:cellForRowIndexPath:
method, it does present the data in the table, but when I go to other view and come back the data disappears because tableView:cellForRowIndexPath:
is not called. Here is the code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"begin of cellForRowAtIndexPath");
SchedualeCell *cell = (SchedualeCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
Course *temp = [array objectAtIndex:indexPath.row];
cell.nameLb.text = temp.name;
cell.hourLb.text = [NSString stringWithFormat:@"%d",temp.hour];
cell.startTimeLb.text = temp.startTime;
cell.endTimeLb.text = temp.endTime;
NSLog(@"End of cellForRowAtIndexPath");
return cell;
}
tableView:numberOfRowsInSection:和
numberOfSectionsInTableView:
。
PS: view是
UIViewController
里面有表视图,我在发布问题之前搜索了所有StackOverflow。
P.S.: The view is
UIViewController
that has table view inside of it, and I searched all StackOverflow before posting my problem.
编辑:这是我设置委托和数据源的地方
EDIT : this is where I set the delegate and datasource
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Did Appear");
// Do any additional setup after loading the view.
self.view.layer.shadowOpacity = 0.75f;
self.view.layer.shadowRadius = 10.0f;
self.view.layer.shadowColor= [UIColor blackColor].CGColor;
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]])
{
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
if (array == nil)
{
array = [[NSMutableArray alloc]init];
}
table.delegate = self;
table.dataSource = self;
[table reloadData];
}
我确实包含了标题中的委托和数据源
and I did included The delegate and datasource in the header
@interface MainViewController : UIViewController<UITableViewDataSource , UITableViewDelegate,addDelegate>
推荐答案
首先,它不是
numberOfRowsAtSection
和 numberOfTableView
。它是 numberOfSectionsInTableView
和 numberOfRowsInSection
。
First of all , it's not
numberOfRowsAtSection
and numberOfTableView
. It's numberOfSectionsInTableView
and numberOfRowsInSection
.
物联网你可以这样做:
1)
NSLog
你的 numberOfRowsInSection
。请注意,如果它为0,则永远不会调用 cellForRowAtIndexPath
。
1)
NSLog
your numberOfRowsInSection
. Note that , If it's "0" then your cellForRowAtIndexPath
is never going to be called.
2 )如果您在某些
UIView
中使用 UITableView
,那么您应该添加:
2) If you are using your
UITableView
inside some UIView
then you should add :
[self.view addSubview:table];
3)不要忘记包括:
@interface yourViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
这篇关于不调用CellForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!