问题: 新建一个tableview,在设置数据源时,如果不retain一下数组的话,就会崩溃: array = [NSArray arrayWithObjects: @"1",@"2",@"3",@"4",@"5", nil]; [array retain]; 报错信息: -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x4b436d0 新建tableview最精简的代码: - (void)viewDidLoad { [super viewDidLoad]; UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; tableView.delegate = self; tableView.dataSource = self; array = [NSArray arrayWithObjects: @"1",@"2",@"3",@"4",@"5", nil]; [array retain]; self.view = tableView; [tableView release]; }
http://www.codeios.com/thread-107-1-1.html
http://book.51cto.com/art/200904/117670.htm
http://www.cocoachina.com/iphonedev/sdk/2010/0126/388.html
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Heiti SC Light'}
http://c.gzl.name/archives/tag/uitableview
http://www.cocoachina.com/iphonedev/sdk/2010/1018/2201.html
http://zcg9033586.blog.163.com/blog/static/175217310201112144729380/
http://www.cnblogs.com/Snowfun/archive/2011/05/14/2046338.html
http://www.cocoachina.com/bbs/simple/?t52979.html
http://hi.baidu.com/%B7%B6%BF%A1%D3%C2/blog/category/iphone%BF%AA%B7%A2%C0%FA%B3%CC
本文介绍了一个TableView设置数据源时遇到的崩溃问题及解决方法。当使用NSArray作为数据源且未进行retain操作时,可能会导致程序崩溃。文章提供了一段最小可复现问题的代码示例,并附上了相关链接供进一步研究。
485

被折叠的 条评论
为什么被折叠?



