开发者

Duplication in Uitableview cell?

开发者 https://www.devze.com 2023-03-30 21:53 出处:网络
i got tired from trying all night to solve this issue at the begining my issue is when i add a new data it stored the data into NSMutableArray and in the cellForRowAtIndexPath i show the data, because

i got tired from trying all night to solve this issue at the begining my issue is when i add a new data it stored the data into NSMutableArray and in the cellForRowAtIndexPath i show the data, because i have sections so what i did was as follow

if(indexPath.section == 0)
{
    for (NSDictionary *dictt in data) {
        if ([[dictt objectForKey:@"Type"] isEqualToString:@"Electricity"]) {
            NSLog(@"%@",[dictt objectForKey:@"Account"]);
            cell.textLabel.text = [dictt objectForKey:@"Account"];
            cell.detailTextLabel.text = [dictt objectForKey:@"Type"]; 
            [mainTableView reloadInputViews];
        }



    }  

}

When it comes to final result it show this first

Duplication in Uitableview cell?

when i add another data it show this

Duplication in Uitableview cell?

and if their is a data in another section let say water and when i delete that it starts deleting from Electricity section

and here is the delete function:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

[data removeObjectAtIndex:indexPath.row]; [tableView

deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];

[self saveData];

[mainTable开发者_Go百科View reloadData]; }


You are using the same array for all of your sections, so you definitely want to get a better data structure in place. In your delete function you aren't checking the section of the tableview, so that's why it's deleting from the wrong section.

Basically, you want to create an array that contains arrays of data for each section, so that in your master array the object at index 0 is the array for section 0 etc.

0

精彩评论

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