【发布时间】:2011-07-20 13:14:08
【问题描述】:
if (indexPath.row % 2 == 0) {
// EVEN
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EvenCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f)
blue: (241.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
cell.textLabel.text = [items objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
} else {
// ODD
cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OddCell"] autorelease];
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f)
blue: (180.0/255.f) alpha: 1.0];
bg.backgroundColor = colour;
cell.backgroundView = bg;
cell.textLabel.backgroundColor = bg.backgroundColor;
[bg release];
cell.textLabel.text = [items objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
return cell;
}
这是我的自定义单元格。第一个是偶数,第二个是奇数。我的数组有 194 个元素,但是当我运行应用程序时,我只能在第 10 个元素之后看到 10 个元素,它再次转到第一个元素给我相同的 10 个元素。谁能告诉我这里出了什么问题?
【问题讨论】:
-
这里没有错...
numberOfRows返回什么?错误一定存在 -
我检查了项目数组 NSLog(@"%d",[items count]);它给了我 194 我从 url 读取它们并给了我真实的数字以及我如何查看行数
-
是这个方法返回的数字吗?
-
不,我在 - (void)viewDidLoad { [super viewDidLoad]; NSURL *URL=[NSURL URLWithString:@"trevesstudios.com/osman"]; NSString *content=[NSString stringWithContentsOfURL:URL 编码:NSUTF8StringEncoding 错误:nil]; NSString *list=[content stringByReplacingOccurrencesOfString:@"
"withString:@"" ]; NSArray *listItems = [list componentsSeparatedByString:@"\n"]; array=[listItems retain]; NSLog(@"%d",[items count]);
标签: iphone objective-c uitableview uinavigationcontroller