继续学习tableview

本文介绍了一个TableView设置数据源时遇到的崩溃问题及解决方法。当使用NSArray作为数据源且未进行retain操作时,可能会导致程序崩溃。文章提供了一段最小可复现问题的代码示例,并附上了相关链接供进一步研究。

问题: 新建一个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://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值