开发者

Values are getting cleared from UITableViewCell while scrolling

开发者 https://www.devze.com 2023-03-17 19:27 出处:网络
I have placed three buttons over UITableViewCell and its background is set to an unselect radio button image.

I have placed three buttons over UITableViewCell and its background is set to an unselect radio button image.

While clicking the button I'm again setting the background image as select button.

In a row one select button should persist but while scrolling UITableView all the selected button images are getting cleared

Can somebody please give m开发者_如何学运维e any idea how to do this in this way or in other way ?


You probably are not reusing the cells correctly. When you scroll, a previous cell is reused by the UITableView, but you don't change its contents correctly. Here is a sample code for ur reference

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
    }

    cell.textLabel.text = [urDataArray objectAtIndex:indexPath.row];
    return cell;
}


save the state of you button in table datasource. set that value to your button. table is reloading each displayed row while scrolling.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号