Ios 行的UItableView单元格中的应用程序崩溃

Ios 行的UItableView单元格中的应用程序崩溃,ios,uitableview,nsarray,Ios,Uitableview,Nsarray,我正在尝试使用tableView创建一个示例应用程序,并在该tableView上填充NSArray。每次我使用声明数组时滚动,它都会崩溃 NSArray *listItems = @[]; 当我将数组声明更改回 NSArray * listItems = [[NSArray alloc]initWithObjects:@"a", @"b", @"c", @"d", @"e", @"f", @"g"

我正在尝试使用tableView创建一个示例应用程序,并在该tableView上填充NSArray。每次我使用声明数组时滚动,它都会崩溃

NSArray *listItems = @[];
当我将数组声明更改回

NSArray * listItems = [[NSArray alloc]initWithObjects:@"a",

        @"b",
        @"c",
        @"d",
        @"e",
        @"f",
        @"g",
        @"h",
        @"i",
        @"j",
        @"k",
        @"l",
        @"m",
        @"n",
        @"o",
        @"p",
        @"q",
        @"r",
        @"s",
        @"t",
        @"u",
        @"v",
        @"w",
        @"x",
        @"y",
        @"z",
        @"1",
        @"2",
        @"3 ",
        @"4 ",
        @"5 ",
        @"6 ",
        @"7 ",
        @"8 ",
        @"9",
        @"0",
        @"12",nil]retain];
它很好用。两者的区别是什么?iam使用非圆弧环境。这是我的密码

#import "MyPopOverView.h"



@implementation MyPopOverView

@synthesize tableListiTems;

@synthesize lists;

@synthesize listDict;






/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    tableListiTems.delegate = self;
    tableListiTems.dataSource = self;

    listDict = @{
                 @"a":
                 @"b", // Register,
                 @"c":
                 @"d",
                 @"e":
                 @"f",
                 @"g":
                 @"h",
                 @"i":
                 @"j",
                 @"k":
                 @"l ",
                 @"m":
                 @"n"};



    lists = @[
        @"a",
        @"b",
        @"c",
        @"d",
        @"e",
        @"f",
        @"g",
        @"h",
        @"i",
        @"j",
        @"k",
        @"l",
        @"m",
        @"n",
        @"o",
        @"p",
        @"q",
        @"r",
        @"s",
        @"t",
        @"u",
        @"v",
        @"w",
        @"x",
        @"y",
        @"z",
        @"1",
        @"2",
        @"3 ",
        @"4 ",
        @"5 ",
        @"6 ",
        @"7 ",
        @"8 ",
        @"9",
        @"0",
        @"12",
];


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [lists count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [lists objectAtIndex:indexPath.row];

    return cell;
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
返回自动释放的对象:
[NSArray数组]
。 请添加并保留:

NSArray *listItems = @[].retain;

注意:别忘了释放它。

列表数组的属性是什么,何时崩溃?崩溃是什么?使用备用数组声明时,是否仍保留它?你为什么不使用ARC?它是旧代码还是你只是内存泄漏的粉丝:)?我在问题中提到它只有在我滚动tableview时才会崩溃。属性是(非原子的,保留)如果它是属性,你应该使用
self.lists=…
设置它,以便保留它。苹果的文档和成百上千的答案中都包含了这一点。
NSArray *listItems = @[].retain;