不调用CellForRowAtIndexPath

编程入门 行业动态 更新时间:2024-10-23 23:29:40
本文介绍了不调用CellForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个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

本文发布于:2023-10-28 19:18:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CellForRowAtIndexPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!