前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Table View滑动时报错

Table View滑动时报错

作者头像
猿人谷
发布2018-01-17 10:27:59
4780
发布2018-01-17 10:27:59
举报
文章被收录于专栏:猿人谷

学习表视图(Table View)的应用时,自己写了个demo,最后表格出来了,可是滑动时报错了,报错如下:

这是我ViewController.m部分的代码:

代码语言:javascript
复制
 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 
 5 @end
 6 
 7 @implementation ViewController
 8 {
 9     NSArray *tableData;
10 }
11 
12 - (void)viewDidLoad
13 {
14     [super viewDidLoad];
15     // Do any additional setup after loading the view, typically from a nib.
16     tableData = [NSArray arrayWithObjects:@"Egg Benedict" , @"Mushroom Risotto" , @"Full Breakfast" , @"Hamburger" ,@"Ham and Egg Sandwich" , @"Creme brelee" , @"white chocolate donut" , @"starbucks coffee" , @"vegetable curry" , @"instant noodle with egg" , @"noodle with bbq pork" , @"japanese noodle" , @"green tea" , @"thai shrimp cake" , @"angry birds cake" , @"ham and cheese panini" , nil];
17     //[tableData retain];
18 
19 }
20 
21 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
22 {
23     return [tableData count];
24     
25 }
26 
27 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
28 {
29     static NSString *simpleTableIdentifier = @"SimpleTableItem";
30     
31     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
32     
33     if (cell == nil) {
34         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
35     }
36     
37     //[[cell textLabel] setText:[tableData objectAtIndex:[indexPath row]]];
38     cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
39     cell.imageView.image = [UIImage imageNamed:@"icon.png"];
40     
41     
42     return cell;
43     
44 }
45 
46 - (void)didReceiveMemoryWarning
47 {
48     [super didReceiveMemoryWarning];
49     // Dispose of any resources that can be recreated.
50 }
51 
52 @end

经过反复的测试后,解决办法如下:

在第17行加上:

代码语言:javascript
复制
[tableData retain];

这样就可以解决报错问题了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-02-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档