Hii Ich bin neu in ios developer.Ich möchte Zeile in tableview.Ich werde den Code implementieren, aber wenn ich die Tabellendarstellung als klicken Sie auf Schaltfläche löschen als Anzeige Fehler[__NSCFArray removeObjectAtIndex:]: mutierende Methode an unveränderliches Objekt gesendet
[__NSCFArray removeObjectAtIndex:]: Mutieren Methode unveränderliches Objekt‘gesendet
hier ist mein Screenshot
hier ist mein Code
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return [cart_data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *simpleTableIdentifier = @"cellitem";
cell *cells = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cells == nil) {
cells = [[cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cells.lbl_title.text = [NSString stringWithFormat:@"%@",cart_data[indexPath.row][@"name"]];
cells.lbl_price.text = [NSString stringWithFormat:@"%@",cart_data[indexPath.row][@"price"]];
cells.lbl_qty.text = [NSString stringWithFormat:@"%@",cart_data[indexPath.row][@"qty"]];
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@",cart_data[indexPath.row][@"img_url"]]];
[cells.image setImageWithURL:url placeholderImage:[UIImage imageNamed:@"imagename"] ];
return cells;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[cart_data removeObjectAtIndex:indexPath.row];
[self.table deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.table reloadData];
//add code here for when you hit delete
}
}
mir helfen, eine Lösung ... Dank für Fortschritt
Ich denke, dass '' cart_data' ein NSArray' ist und kein 'NSMutableArray'. – Larme
Warenkorb Daten nsmutablearray.bcs sie Daten kommen in dem Server – dany
cart_data Mit NSMutableArray zu erklären und überprüfen, ob (cart_data.count> indexpath.row) -> THE DELTEE –