我与indexPath.section
从cellForRowAtIndexPath:
方法一个奇怪的问题。怪异的行为“的cellForRowAtIndexPath:”
我有4段分组的实现代码如下,我尝试应用自定义UITableViewCell
为第3,但它不工作。
当我尝试if(indexPath.section==0){...}
它的工作(并为section==1
和section==2
以及),但它失败section==3
。 (?)
我不知道为什么,那是没有意义的..是不是有人已经有了这样(怪)的问题?
当我尝试if(indexPath.row==0){...}
它适用于所有的4个部分..所以..?!
这里是我的代码:
//ViewController.h
import "DirectionsTableViewCell.h"
DirectionsTableViewCell *directionsCell; // customized UITableViewCell
//ViewController.m
if (indexPath.section==3) {
static NSString *CellIdentifier = @"directionsCell";
DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
cell = directionsCell;
}
return cell;
}
else {
static NSString *CellIdentifier = @"defaultCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Test";
return cell;
}
问题解决了!
我只是说if(indexPath.row)
并能正常工作。
最后你得到这个:
if(indexPath.section==3) {
if(indexPath.row) {
static NSString *CellIdentifier = @"directionsCell";
DirectionsTableViewCell *cell = (DirectionsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DirectionsTableViewCell" owner:self options:nil];
cell = directionsCell;
}
return cell;
}
}
在何种意义上失败?你得到什么错误或意外的结果? – PengOne 2012-01-12 23:13:48
我其实有这个问题。你可以发布你的'cellForRowAtIndexPath'方法吗?这可能有助于确认我的预感。 – 2012-01-12 23:16:01
好吧,我没有任何错误,但它不加载自定义UITableViewCell ..我仍然有默认的。 – bs7 2012-01-12 23:16:59