TableView的cellForRowAtIndexPath不执行

tyrcui 2014-02-26 08:36:42
TableView的cellForRowAtIndexPath不执行,不过NumberofRow这个函数返回的值是正确的,包括NumberofSections的值也没问题。
我用的是Storyboard, 自己定义的TableView,
能执行到 NumberofRow, 就是不执行cellForRow!
在xcode4中 xib下是没问题的
我在xcode5中用了Storyboard, 代码是一样的, 包括定义的也都是一样的, 结果不显示! 是不是有什么绑定我没做到?



ViewController.h:

@interface ViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>


@property (copy, nonatomic) NSMutableArray *prjlist;
@property (nonatomic, strong) UITableView *mytable;


.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [self.prjlist count];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView


{
NSLog(@"%i", self.prjlist.count); //能执行到,值正确
return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//不执行
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

NSMutableDictionary *prjinfo = self.prjlist[indexPath.row];

cell.textLabel.text = [prjinfo objectForKey:@"prj_name"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;

}
...全文
2237 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
头发还没秃a 2016-04-14
  • 打赏
  • 举报
回复
引用 11 楼 u010189308 的回复:
解决了,我只实现了 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 没有实现 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 粗心。。。。 实现numberofRowsInSection就会调用cellForRowAtIndexPath了,当然前提是你storyBoard里把tableView控件的datasource和delegate连上你的viewcontroler
swift里面numberofRowsInSection这个方法是可选的啊,不实现也可以运行cellForRowAtIndexPath代理
西班牙饼干 2016-04-14
  • 打赏
  • 举报
回复
解决了,我只实现了 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 没有实现 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 粗心。。。。 实现numberofRowsInSection就会调用cellForRowAtIndexPath了,当然前提是你storyBoard里把tableView控件的datasource和delegate连上你的viewcontroler
西班牙饼干 2016-04-14
  • 打赏
  • 举报
回复
楼主解决了吗?我的也不执行tableView: cellForRowAtIndexPath: 方法,楼主解决了吗
ffow10 2015-05-15
  • 打赏
  • 举报
回复
1.设置代理 self.mytable.delegate = self; self.mytable.dataSource = self; 2.UI处理只能在主线程, [self.mytable reloadData]需要在主线程执行
梦一场Monster 2015-05-15
  • 打赏
  • 举报
回复
storyBorad中需要手动连接代理,关联viewController还有indefinitely,你看看都有操作么,有的话,看看是不是关联错地方了
明雨夏 2015-05-13
  • 打赏
  • 举报
回复
我遇到这个问题了。。。
术木 2014-02-26
  • 打赏
  • 举报
回复
你在storyboard 操作了? 要拖一下的。 要不他哪知道是哪个tableview要用啊。
tyrcui 2014-02-26
  • 打赏
  • 举报
回复
就是在头文件里的 ViewController.h: @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
术木 2014-02-26
  • 打赏
  • 举报
回复
tyrcui 2014-02-26
  • 打赏
  • 举报
回复
这个也设置过了的 我用的mknetworkkit获取的数据 因为是异步的, 所以我用了 [self.mytable reloadData] 在xcode4下, reload数据就出来了 在xcode5下面 就不显示了
gxingmin 2014-02-26
  • 打赏
  • 举报
回复
- (void)viewDidLoad { self. mytable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; self. mytable.separatorStyle = UITableViewCellSeparatorStyleNone; self. mytable.delegate = self; self. mytable.dataSource = self; ... }
tyrcui 2014-02-26
  • 打赏
  • 举报
回复
我是自己定义的tableview UITableView *mytable 我在storyboard里拖到哪里呢?

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧