Ios 当上一节不在屏幕上时,UITableView节
我正在开发一个iPhone应用程序,在检查分组表视图的部分时遇到了一些问题。当第一部分不再可见时,因为我向下滚动了tableview,tableview反弹回来,第二部分从第一部分获取设置?我使用indexPath.section值检查它是哪个节。我怎样才能解决这个问题?对不起,如果我的英语不正确 很抱歉丢失了代码! 下面是cellForRowAtIndexPath代码的一部分:Ios 当上一节不在屏幕上时,UITableView节,ios,iphone,xcode,uitableview,Ios,Iphone,Xcode,Uitableview,我正在开发一个iPhone应用程序,在检查分组表视图的部分时遇到了一些问题。当第一部分不再可见时,因为我向下滚动了tableview,tableview反弹回来,第二部分从第一部分获取设置?我使用indexPath.section值检查它是哪个节。我怎样才能解决这个问题?对不起,如果我的英语不正确 很抱歉丢失了代码! 下面是cellForRowAtIndexPath代码的一部分: - (UITableViewCell *)tableView:(UITableView *)tableVie
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(indexPath.section == 0){
pinSwitch.hidden = YES;
cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
if([headarray count] != 0){
if(indexPath.row > [headarray count] - 1){
cell.imageView.alpha = 0;
cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];
}
else{
cell.imageView.alpha = 1;
NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
cell.textLabel.text = [infoarray objectAtIndex:0];
}
}
}
else if(indexPath.section == 1){
if(indexPath.row == 0){
//some more cell data
}
我想这足以说明我的问题 粘贴单元生成代码,似乎您没有正确使用重用单元机制 编辑: 代码不完整,我认为您应该这样做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(indexPath.section == 0){
pinSwitch.hidden = YES;
cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
if([headarray count] != 0){
if(indexPath.row > [headarray count] - 1){
cell.imageView.alpha = 0;
cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];
}
else{
cell.imageView.alpha = 1;
NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
cell.textLabel.text = [infoarray objectAtIndex:0];
}
}
}
else if(indexPath.section == 1){
if(indexPath.row == 0){
// you should fill cell data for all cases !!!!
}
} else { // for example
cell.imageView.alpha = 1;
NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
cell.textLabel.text = [infoarray objectAtIndex:0];
}
你的问题有点漫无边际。请提供一些代码,并解释你想做什么样的检查?特别是,如果你能向我们展示你的
cellforrowatinexpath:
,我们应该能够找到答案。是的,我做到了!对不起,误会了!我填了所有的手机数据!但如果第一部分不可见,则第二部分的单元格将获取第一部分的一些单元格数据