Data repeat in UITableView when scrolling

前端 未结 4 1896
青春惊慌失措
青春惊慌失措 2020-12-10 22:46

I use bellow codes to show data on TableView but when scrolling, data repeat and other data lost.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tab         


        
4条回答
  •  鱼传尺愫
    2020-12-10 23:43

    use cell Identifier different

    For example like bellow...

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];
    
        UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            /// write your code here..
        }
    }
    

    OR set nil like bellow..

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        //static NSString *CellIdentifier = @"CellIdentifier";    
    
        UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:nil];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
            /// write your code here..
        }
    }
    

提交回复
热议问题