- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}-----------------------------------------------------------
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
iostableview
{
static NSString *simpleTableIdentifier = @"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}-----------------------------------------------------------
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
iostableview
解决方案 »
- Cannot run on the selected destination
- UITableView如何独立设置每个Cell的左边的图片
- iOS tableview 往下滑动后,上面的多选效果没了,不过数据还在
- ipad开发,屏幕翻转控件大小适应问题
- iOS下,phonegap如何创建sqlite数据库
- iOS如何获取系统时间
- tableView实现横向
- 开发一个类似周边服务(培训)的APP需要的周期
- 刚切入到UITabBarController只显示第一个按钮
- iOS 使用Platinum实现DLan时,用模拟器会出现提示,用真机什么也搜不到
- 如何一次发送多个推送到不同token的手机啊 ?
- 苹果手机越狱 固件 软件一系列 回帖可得到链接
第二种创建方法就是每一个数据都创建一个cell,例如:页面显示5个cell,实际有10条数据,第6个数据出现时又创建了一个cell,第一个cell却放着不用,这种方法10个数据创建了10个cell,每次只显示5个,另外5个放着不显示。。浪费空间
NSString* data=[NSString alloc]init…………
NSString* data=[NSString stringwith……
这三个有什么区别呢??
该怎么判断是第一个tableview还是第二个tableview呢??
NSString* data=@"123"; //常量字符串
NSString* data=[NSString alloc]init…… //初始化NSString,方法为NSString的成员函数,根据自己的需要手动指定是否autorelease
NSString* data=[NSString stringwith…… //同上,只是方法为NSString的静态方法,且默认为autorelease的
2)UIView有个tag属性,可以根据不同的tableview设置tag进行区分。
你二种是这样的,以下两个写法都一样,根据自己的使用习惯:
NSString* data=[[NSString alloc] init];
...//do something
[data release];
或者
NSString* data=[[[NSString alloc] init] autorelease];
...//do something
那前两种,就是字符常亮串和alloc的,生成的对象在内存里,都放在哪呢?
可以参考下这里的Creating Strings说明:https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Strings/Articles/CreatingStrings.html字符串常量的话,在编译程序时就已经确定好了字符空间大小,程序加载时就会分配好对应的地址,程序关闭时才会释放,整个程序运行过程中不用去释放。
而alloc出来的NSString则是动态分配与释放。
你的写法应该更可靠些,不过如果不是ARC环境的话,你的cell alloc的时候忘了最后加autorelease;
谢谢指点。我没用过ARC,问一下,平时你们写程序是用ARC多还是不用ARC多呢??
非ARC的情况多吧,一方面方便兼容低版本的IOS系统版本,另一方面也好自己控制内存,查内存泄露什么的。