2016-10-03 1 views
0

Ниже мой код и ячейки переписываются, когда я прокручиваю и когда я помещаю контент в if (cell == nil), ничего не отображается, я не знаю, как избавиться от него. , когда я прокручиваю снова и снова, это только перезапись.Перезапись ячейки таблицы

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
[tableView deselectRowAtIndexPath:indexPath animated:NO]; 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    } 
    UILabel *boothtitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 3, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *HouseTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 31, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *NameTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 59, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *FHNTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 87, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *EPICTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 115, self.view.frame.size.width*0.5-3, 25)]; 

    UILabel *BoothNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 3, 200, 25)]; 
    UILabel *HouseNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 31, 200, 25)]; 
    UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 59, 200, 25)]; 
    UILabel *EPIC=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 87, 200, 25)]; 
    UILabel *Fnaaam=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 115, 200, 25)]; 

    [cell.contentView addSubview:boothtitle]; 
    [cell.contentView addSubview:HouseTitle]; 
    [cell.contentView addSubview:NameTitle]; 
    [cell.contentView addSubview:FHNTitle]; 
    [cell.contentView addSubview:EPICTitle]; 

    [cell.contentView addSubview:BoothNo]; 
    [cell.contentView addSubview:Name]; 
    [cell.contentView addSubview:HouseNo]; 
    [cell.contentView addSubview:EPIC]; 
    [cell.contentView addSubview:Fnaaam]; 
    [email protected]"Booth Number"; 
    [email protected]"House Number"; 
    [email protected]"Name"; 
    [email protected]"F/H/M Name"; 
    [email protected]"EPIC"; 

    BoothNo.text=[BotthID objectAtIndex:indexPath.row]; 
    Name.text=[nname objectAtIndex:indexPath.row]; 
    HouseNo.text=[Houseno objectAtIndex:indexPath.row]; 
    EPIC.text=[EpiC objectAtIndex:indexPath.row]; 
    Fnaaam.text=[FName objectAtIndex:indexPath.row]; 

    return cell; 

} 
+0

@Shikha Я думаю, вам следует попытаться работать с рассказчиком. поместите один столбец в UIVIewController и добавьте один TableviewCell в Tableview и добавьте свою метку в ячейку, создайте ее и получите доступ к этим меткам с тегом в этом методе - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {} если вы хотите работать с этим, я загружаю этот метод. –

+0

@HemsMoradiya использует только раскадровку –

+0

@NiravD ошибка, необъявленные идентификаторы. :( –

ответ

0

Я решил это, я просто изменил состояние. Ниже приведен код.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell != nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    } 
    UILabel *boothtitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 3, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *HouseTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 31, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *NameTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 59, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *FHNTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 87, self.view.frame.size.width*0.5-3, 25)]; 
    UILabel *EPICTitle=[[UILabel alloc]initWithFrame:CGRectMake(3, 115, self.view.frame.size.width*0.5-3, 25)]; 
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.5+90, 7, 25, 25)]; 

    icon.image=[UIImage imageNamed:@"edit.png"]; 

    UILabel *BoothNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 3, 200, 25)]; 
    UILabel *HouseNo=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 31, 200, 25)]; 
    UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 59, 200, 25)]; 
    UILabel *EPIC=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 87, 200, 25)]; 
    UILabel *Fnaaam=[[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.5+3, 115, 200, 25)]; 

    [cell.contentView addSubview:boothtitle]; 
    [cell.contentView addSubview:HouseTitle]; 
    [cell.contentView addSubview:NameTitle]; 
    [cell.contentView addSubview:FHNTitle]; 
    [cell.contentView addSubview:EPICTitle]; 

    [cell.contentView addSubview:icon]; 

    [cell.contentView addSubview:BoothNo]; 
    [cell.contentView addSubview:Name]; 
    [cell.contentView addSubview:HouseNo]; 
    [cell.contentView addSubview:EPIC]; 
    [cell.contentView addSubview:Fnaaam]; 
    [email protected]"Booth Number"; 
    [email protected]"House Number"; 
    [email protected]"Name"; 
    [email protected]"F/H/M Name"; 
    [email protected]"EPIC"; 

    BoothNo.text=[BotthID objectAtIndex:indexPath.row]; 
    Name.text=[nname objectAtIndex:indexPath.row]; 
    HouseNo.text=[Houseno objectAtIndex:indexPath.row]; 
    EPIC.text=[EpiC objectAtIndex:indexPath.row]; 
    Fnaaam.text=[FName objectAtIndex:indexPath.row]; 

    return cell; 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^