Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Objective C by registered user tarunsachdeva001 ( 10 years ago )
#pragma mark - UITableView Delegate Methods
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Detemine if it's in editing mode
//    if (tableView.editing)
//    {
//        return UITableViewCellEditingStyleDelete;
//    }
    return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [portfolioDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EditPortpolioCell *cell = (EditPortpolioCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"EditPortpolioCell" owner:self options:nil];
        cell = (EditPortpolioCell *)[nib objectAtIndex:0];
    }
    
    cell.modelImage.imageURL =  [NSURL URLWithString:[[portfolioDataArray objectAtIndex:indexPath.row]valueForKey:@"big_image"]];
    return  cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
     deleteIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        selectedPhotoID = [[NSString alloc]initWithString:[[portfolioDataArray objectAtIndex:indexPath.row]valueForKey:@"photo_id"]];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Model Launcher" message:@"Do you really want to delete this photo!" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
            [self deletePhotoFromServer];
        }];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
            [tableView reloadRowsAtIndexPaths:@[deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        }];
        [alert addAction:cancelAction];
        [alert addAction:okAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    [portfolioDataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
    [portfolioTableView reloadData];
}

 

Revise this Paste

Your Name: Code Language: