• Table View滑动时报错


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

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

     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行加上:

    [tableData retain];

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

  • 相关阅读:
    HCTF2018-admin
    SUCTF 2019-EasySQL
    BUUCTF-WEB-easy_tornado
    黑客攻防技术宝典web实战篇:攻击数据存储区习题
    可持久化数据结构·主席树(静态)
    Luogu P2661 [NOIP2015] 信息传递
    Luogu P2700 逐个击破
    Luogu P4779 【模板】单源最短路径(标准版)(Dijkstra+堆优化模板)
    Luogu P1962 斐波那契数列(矩阵乘法模板)
    Luogu P3366 【模板】最小生成树
  • 原文地址:https://www.cnblogs.com/heyonggang/p/3556568.html
Copyright © 2020-2023  润新知