2014-09-21 2 views
0

parse.com에서 데이터를로드하고 표시하는 UITableview가 있습니다. 그리고 나는 이것이 사용자가 parse.com에서 그것을 삭제 테이블보기에서 항목을 삭제하면 그래서 난 내 자신의 tableview를 사용했다UITableView에서 항목 제거 - Parse.com에서 데이터 가져 오기

편집 할 수 및 사용자 정의 셀 parseSimpleCell.h,하는 .m를 사용하려면

여기

내있는 tableview의 .H와하는 .m 파일을 여기에

#import <UIKit/UIKit.h> 
#import <Parse/Parse.h> 
#import "ParseExampleCell.h" 

@interface FavoritesTableViewController : UITableViewController <UITableViewDelegate,UITableViewDataSource> { 
    NSArray *itemsArray; 
} 

@property (weak, nonatomic) IBOutlet UITableView *favItemsTable; 

@end 

#import "FavoritesTableViewController.h" 

@interface FavoritesTableViewController() 

@end 

@implementation FavoritesTableViewController 



- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self performSelector:@selector(retrieveFromParse)]; 


    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

- (void) retrieveFromParse { 

    PFUser *currentUser = [PFUser currentUser]; 

    PFQuery *query = [PFQuery queryWithClassName:@"UserFavourite"]; 
    [query whereKey:@"userIdString" equalTo:currentUser.objectId]; 
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) { 
      itemsArray = [[NSArray alloc] initWithArray:objects]; 
     } 
     [_favItemsTable reloadData]; 
    }]; 
} 



#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 

    return itemsArray.count; 

} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    ParseExampleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    PFObject *tempObject = [itemsArray objectAtIndex:indexPath.row]; 

    cell.cellTitle.text = [tempObject objectForKey:@"item"]; 


    cell.tintColor = [UIColor redColor]; 

    return cell; 

} 


// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Return NO if you do not 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 { 


} 


@end 

나는이 방법 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {에서 어떤 일이 일어나는지에 도움이 필요로하는 .m 파일입니다입니다

나는 다른 질문을 보았지만 변수가있는 객체를 보았습니다. 즉, getFromParse 메소드는 commitEditing 스타일 메소드에서 사용할 수 없습니다.

나는이

if (editingStyle == UITableViewCellEditingStyleDelete) { 
    PFObject *object = [self.objects objectAtIndex:indexPath.row]; 
    [object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { 
     [self loadObjects]; 
    }]; 
} 

같은 것들을 시도에 불과하다 객체는 당신이 시도한 것은 self.objects을 의미

답변

1

사전에

도움을

감사를 찾을 수 없습니다라고,하지만 난 돈 ' 당신이 사용하는 다른 곳을 보지 마십시오 objects.

테이블에서 삭제하는 방법은 데이터 원본에서 삭제 한 다음 테이블보기에서 삭제하는 것입니다. 파스에서 객체를 삭제하기를 원하기 때문에 추가 단계가 필요합니다.

// remove from datasource 
PFObject *object = itemsArray[indexPath.row]; 
[itemsArray removeObject:object]; 

// tell the table to update 
[tableView beginUpdates]; 
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
[tableView endUpdates 

// remove from parse 
[object deleteInBackground]; 

같은 개체를 즉시 쿼리하면 경쟁 조건이 설정 될 수 있습니다. 그럴만한 위험이있는 경우 deleteInBackgroundWithBlock:을 사용하고 블록에서 로컬 삭제를 수행하십시오.

관련 문제