2014-12-21 6 views
0

좋아, 나는 새로운 딜레마가있다. 나는 S.O. 대답을 찾지 만 코드를 작동시킬 수없는 것 같습니다. 또한 많은 자습서 및 기타 리소스를 살펴 보았지만 도움이 될만한 것을 찾지 못했습니다.사용자 정의 tableview 셀에서 이미지의 선택된 상태를 유지하는 방법은 무엇입니까?

여기 거래가 있습니다. 사용자 정의 객체가있는 사용자 정의 셀이있는 tableview가 있습니다. 사용자 정의 셀에는 셀에 나열된 운송 유형이 사용되었는지 여부를 표시하기 위해 선택할 수있는 이미지가 들어 있습니다. 이미지가 회색으로 표시된 "선택 취소됨"상태에서 파란색의 "선택됨"상태로 변경됩니다 (또는 "선택됨"에서 "선택 취소됨"으로 되돌아갑니다). 이미지의 탭 제스처는 사용자가 "예"또는 "아니오"를 선택할 수있는 경고보기를 시작합니다. 그런 다음 경고보기에서 이미지가 "선택됨"또는 "선택 취소 됨"상태로 변경되며 기본적으로 확인 표시처럼 작동합니다. 이것은 모두 완벽하게 작동합니다. (이미지의 의도하지 않은 탭 제스처에 대한 보호 수단으로 경고보기를 추가했습니다.) 셀 스크롤링 동안 사라진 후 화상이 해제되고, 또 다시 나타나면

http://tinypic.com/r/s5d3s3/8

문제가 발생한다. 많은 사람들이이 문제에 대해 질문했습니다. 내가해야 할 것 같습니다 : (1) 선택을 유지하기 위해 변경할 수있는 배열을 설정하십시오. (2) 셀에 표시 할 내용을 cellForRowAtIndexPath에 몇 가지 수행하여 (3)과 어딘가에 이미지의 상태를 설정하십시오 선택되어 변경 가능한 배열에 추가 될 수 있습니다.

나는 주어진 답변에서 아이디어를 구현하려했지만 많은 사람들이 버튼이나 셀 액세서리를 사용합니다. 문제의 일부는 이미지에 제스처 인식기 및 경고 뷰 실행이 있으므로이 코드 중 일부를 구현하는 부분입니다. 또한 선택 사항을 nsuserdefaults로 저장하면 스크롤하는 동안 이미지의 상태가 유지됩니까? 아니면 두 문제를 별도로 처리해야합니까? (즉, 스크롤하는 동안 상태를 유지하는 코드와 nsuserdefaults에 저장할 코드를 추가하십시오.) 나는 S.O.를 시도했다. nususerdefaults 사용에 대한 대답은 같지만 동일한 문제가 있습니다 ...이 코드는 어디에 두어야합니까? 버튼 상태 또는 셀 액세서리 상태를 저장하는 대신 이미지 상태를 저장하려면 어떻게합니까?

또한 tableview가 내비게이션 컨트롤러에 내장되어 있고 각 셀이 didSelectCellAtIndexPath (대부분의 S.O. 응답에 포함)에 코드를 추가 할 때 문제를 추가하는 세부 정보보기로 이동한다는 점에 유의하고 싶습니다. 전체 셀이 아닌 탭핑 된 이미지를 선택하는 방법 (종종 이미지 선택과 함께 세그가 발생합니다).

모든 종류의 도움을 받으실 수 있습니다 !! 미리 감사드립니다. :)

아래는 내 모든 코드 :

**TRANSPORT.h** 

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 

@interface Transport : NSObject 

@property (nonatomic, strong) NSString *name; 
@property (nonatomic, strong) UIImage *transportImage; 
@property (nonatomic, strong) UIImage *usedTransportImage; 

@end 


**TRANSPORTDATACONTROLLER.h** 

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 
#import "Transport.h" 

@interface TransportDataController : NSObject 

@property (nonatomic, strong) NSMutableArray *transportDataArray; 
-(NSMutableArray *)populateDataSource; 

@end 


**TRANSPORTDATACONTROLLER.m** 

#import "TransportDataController.h" 

@implementation TransportDataController 

-(NSMutableArray *)populateDataSource 
{ 
    _transportDataArray = [[NSMutableArray alloc] init]; 
    Transport *transportData = [[Transport alloc] init]; 

    transportData.name = @"Bus"; 
    transportData.transportImage = [UIImage imageNamed:@"Bus"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Helicopter"; 
    transportData.transportImage = [UIImage imageNamed:@"Helicopter"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Truck"; 
    transportData.transportImage = [UIImage imageNamed:@"Truck"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Boat"; 
    transportData.transportImage = [UIImage imageNamed:@"Boat"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Bicycle"; 
    transportData.transportImage = [UIImage imageNamed:@"Bicycle"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Motorcycle"; 
    transportData.transportImage = [UIImage imageNamed:@"Motorcycle"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Plane"; 
    transportData.transportImage = [UIImage imageNamed:@"Plane"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Train"; 
    transportData.transportImage = [UIImage imageNamed:@"Train"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Car"; 
    transportData.transportImage = [UIImage imageNamed:@"Car"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Scooter"; 
    transportData.transportImage = [UIImage imageNamed:@"Scooter"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    transportData = [[Transport alloc] init]; 
    transportData.name = @"Caravan"; 
    transportData.transportImage = [UIImage imageNamed:@"Caravan"]; 
    transportData.usedTransportImage = [UIImage imageNamed:@"stamp-grayed"]; 
    [_transportDataArray addObject:transportData]; 

    return _transportDataArray; 
} 

@end 


**TRANSPORTCELL.h** 

#import <UIKit/UIKit.h> 

@interface TransportCell : UITableViewCell 

@property (nonatomic, weak) IBOutlet UILabel *nameLabel; 
@property (nonatomic, weak) IBOutlet UIImageView *transportImageView; 
@property (nonatomic, weak) IBOutlet UIImageView *grayedImageView; 

@end 


**MAINTABLEVIEWCONTROLLER.h** 

#import <UIKit/UIKit.h> 
#import "Transport.h" 
#import "TransportDataController.h" 
#import "DetailTableViewController.h" 

@interface MainTableViewController : UITableViewController 

@property (nonatomic, strong) TransportDataController *transportController; 
@property (nonatomic, strong) NSMutableArray *dataSource; 

@end 


**MAINTABLEVIEWCONTROLLER.m** 

#import "MainTableViewController.h" 
#import "TransportCell.h" 

@interface MainTableViewController() 

@end 

@implementation MainTableViewController 

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    _transportController = [[TransportDataController alloc] init]; 
    self.dataSource = _transportController.populateDataSource; 
    self.title = @"Transportation Types"; 

} 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return _dataSource.count; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"mainCell"; 
    TransportCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[TransportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    Transport *transportData = [self.dataSource objectAtIndex:indexPath.row]; 
    cell.nameLabel.text = transportData.name; 
    cell.transportImageView.image = transportData.transportImage; 
    cell.grayedImageView.image = transportData.usedTransportImage; 

    UITapGestureRecognizer *grayedImageTouched = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(transportImageTapped:)]; 
    grayedImageTouched.numberOfTapsRequired = 1; 
    [cell.grayedImageView addGestureRecognizer:grayedImageTouched]; 
    cell.grayedImageView.userInteractionEnabled = YES; 


    return cell; 
} 


-(void)transportImageTapped:(UIGestureRecognizer *)gesture 
{ 
    UIImageView *selectedImageView = (UIImageView *)[gesture view]; 
    UIImage *grayedImage = [UIImage imageNamed:@"stamp-grayed"]; 
    UIImage *darkImage = [UIImage imageNamed:@"stamp-color"]; 

    UIAlertController *transportAlert = [UIAlertController alertControllerWithTitle:@"Yes, it's true..." message:@"I have used this type of transport before." preferredStyle:UIAlertControllerStyleAlert]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){ 

     NSLog(@"cancel"); 

    }]]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

     if (selectedImageView.image == grayedImage) 
     { 
      selectedImageView.image = grayedImage; 
      [selectedImageView setImage:grayedImage]; 

     } 
     else 
     { 
      selectedImageView.image = darkImage; 
      [selectedImageView setImage:darkImage]; 

     } 

     if (selectedImageView.image == darkImage) 
     { 
      selectedImageView.image = darkImage; 
      [selectedImageView setImage:darkImage]; 

     } 
     else 
     { 
      selectedImageView.image = grayedImage; 
      [selectedImageView setImage:grayedImage]; 

     } 

     NSLog(@"has taken this transport before"); 


    }]]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

     if (selectedImageView.image == darkImage) 
     { 
      selectedImageView.image = grayedImage; 
      [selectedImageView setImage:grayedImage]; 

     } 
     else 
     { 
      selectedImageView.image = grayedImage; 
      [selectedImageView setImage:grayedImage]; 
     } 

     if (selectedImageView.image == grayedImage) 
     { 
      selectedImageView.image = grayedImage; 
      [selectedImageView setImage:grayedImage]; 
     } 

     NSLog(@"has not taken this transport before"); 
    }]]; 

    [self presentViewController:transportAlert animated:YES completion:nil]; 

} 


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"showDetail"]) 
    { 
     DetailTableViewController *detailController = [segue destinationViewController]; 
     detailController.transport = [self.dataSource objectAtIndex:[self.tableView indexPathForSelectedRow] .row]; 
    } 
} 

@end 
+0

, 당신은 이미지가 어두워 하시겠습니까? 현재로서는 "예"블록이 실제로 아무 것도하지 않는 것처럼 보입니다 ... –

+0

@ Lyndsey ... Ah! 이것은 내가 언급하는 것을 잊었던 것이다. 방정식에 경고보기를 추가하면 부울 논리가 이상해져 작동하지 않습니다. 위의 코드는 내가 생각해 낸 것입니다. 마치 실제로는 보이지 않더라도 완벽하게 작동합니다. 그 문제는 나에게 꽤 오랫동안 고뇌를 안겨 줬다. 하지만 질문에 대답하기 위해 "예"를 선택하면 이미지가 회색으로 표시되지 않고 어둡게 표시됩니다. – IWannaLearn

+0

좋아, 그게 내가 생각한거야. 내 대답을 확인한 다음 로직을 단순화하는 방법을 확인하십시오. –

답변

0

의심스러운 점이 있으면 cellForRowAtIndexPath이 원하는 이미지를 적절하게로드 할 수 있도록 버튼 클릭시 데이터 소스 데이터를 변경해야합니다. 이 경우 경고보기의 입력에 따라 TransportCellusedTransportImage (즉, 'UIGestureRecognizer'에 연결된 UIImage)을 어둡게 또는 회색으로 변경하면됩니다.

당신의 코드가 지금 그대로이기 때문에 경고 블록 내의 논리에 결함이 있습니다. 당신의 "예"블록은 항상 당신의 이미지를 그대로 남겨 둡니다. "No"블록은 항상 이미지를 회색으로 설정하고 각 블록 내에서 이미지를 여러 번 반복 설정합니다. 나는 당신이 어쩌면 "예"응답을 어둡게 설정하고 usedTransportImage을 회색 (?)으로 설정하는 "아니오"응답을 설정하려고한다고 생각합니다 ... 그래서이 가정을 예제로 사용하면 좋습니다. :

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

    ... 

    // Set the UITapGestureRecognizer's image view's tag to 
    // indexPath.row 
    cell.grayedImageView.tag = indexPath.row; 

    ... 


    return cell; 
} 

- (void)transportImageTapped:(UIGestureRecognizer *)gesture 
{ 
    // Fetch the datasource object associated with the current row 
    Transport *transportData = [self.dataSource objectAtIndex:gesture.view.tag]; 

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:gesture.view.tag inSection:0]; 

    UIAlertController *transportAlert = [UIAlertController alertControllerWithTitle:@"Yes, it's true..." message:@"I have used this type of transport before." preferredStyle:UIAlertControllerStyleAlert]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){ 

     NSLog(@"cancel"); 

    }]]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

     NSLog(@"has taken this transport before"); 

     // Create the image within the block so it's only 
     // created if needed 
     UIImage *darkImage = [UIImage imageNamed:@"stamp-color"]; 

     // Set the Transport object's "used" image to the 
     // darkened image 
     transportData.usedTransportImage = darkImage; 

     // Replace the old Transport object associated with the 
     // current row with the updated Transport object 
     [self.dataSource replaceObjectAtIndex:gesture.view.tag withObject:transportData]; 

     // Reload the table data at that row so it reflects those changes 
     [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone]; 

    }]]; 

    [transportAlert addAction:[UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

     NSLog(@"has not taken this transport before"); 

     // Create the image within the block so it's only 
     // created if needed 
     UIImage *grayedImage = [UIImage imageNamed:@"stamp-grayed"]; 

     // Set the Transport object's "used" image to the 
     // grayed image 
     transportData.usedTransportImage = grayedImage; 

     // Replace the old Transport object associated with the 
     // current row with the updated Transport object 
     [self.dataSource replaceObjectAtIndex:gesture.view.tag withObject:transportData]; 

     // Reload the table data at that row so it reflects those changes 
     [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone]; 

    }]]; 

    [self presentViewController:transportAlert animated:YES completion:nil]; 

} 

그리고 당신은 버튼을 누를시 뷰의 전환 방지에 대한 질문의 두 번째 부분에 대한 도움이 필요한 경우, didSelectRowAtIndexPath:에서 코드를 게시하시기 바랍니다.

+0

@Lyndsey ... 시간을내어이 점을 생각해 주셔서 감사합니다. 그러나 xcode는 indexPath.row와 관련된 첫 번째 행에 적합합니다. 내 투쟁에서 indexpath를 여러 번 호출하려고했던 것을 기억하고 그것을 사용할 장소를 찾을 수 없었습니다. 다른 게시물에서 권장하는대로 호출하기 위해 tableview 속성을 추가하려고했지만 위에 공유 한 미친 코드를 제외하고는 아무 것도 작동하지 않았습니다. 또한, 나는 현재 didSelectRowAtIndexPath를 구현하지 않았기 때문에 아무 것도 작동하지 않았고 현재 진행중인 작업은 필요하지 않습니다. – IWannaLearn

+0

@IWannaLearn 웁스 ... 업데이트 할게. –

+0

@IWannaLearn 업데이트. 보기의 전환에 관해서는, 전환을 만들기 위해 didSelectRowAtIndexPath를 사용하지 않으면 무엇을 사용하고 있습니까? –

2

단계 떨어져 세부에서 당신이 무슨 일을하는지에 대해 생각합니다.

테이블보기는 주문한 물건 컬렉션에 대한 정보를 제공합니다.

데이터 모델이 있습니다. 테이블 뷰는 뷰 객체이고 뷰 컨트롤러는 MVC 디자인 패턴의 컨트롤러 객체입니다.

사용자가 지속적으로 변경해야하는 방식으로보기와 상호 작용할 때 컨트롤러는 변경 사항을 모델에 기록하고보기에 업데이트 모양을 알려야합니다.

그런 다음 셀이 화면 밖으로 스크롤 한 다음 다시 화면에 나타나면 데이터 소스는 재활용 된 셀을 데이터 모델의 해당 항목에 대한 새 상태로 설정해야합니다.

섹션 화되지 않은 테이블 뷰의 경우 데이터 모델을 일종의 데이터 객체의 NSArray로 저장하는 것이 일반적입니다. 사용자 지정 데이터 컨테이너 개체를 만들거나 사전을 사용할 수 있습니다.

맞춤 데이터 개체가 있다고 가정 해 보겠습니다.

운송 품목의 사용 여부를 알려주는 속성을 데이터 개체에 추가하기 만하면됩니다.

사용자가 뷰 객체를 탭하면 뷰 컨트롤러는 특정 인덱스 경로에 대해 데이터 모델 객체의 "has been used"속성을 변경하여 제스처 인식기의 메시지에 응답 한 다음 자체를 다시 그립니다.

cellForRowAtIndexPath 메서드에서 "has been used"플래그의 상태를 기반으로 뷰 객체를 설정하십시오. 상태 변경을 데이터 모델에 저장 했으므로 다음에 사용자가 테이블 데이터에 지정된 인덱스에 대한 셀을 표시하면 변경된 상태가 표시됩니다.

+0

@Duncan ... 설명해 주셔서 감사합니다. 나는 이것을 인쇄하고 정보를 소화 할 것이다. 모든 것이 학습 경험입니다. :) – IWannaLearn

+0

@Duncan ... 나는 당신의 제안을 조사하고있다. 위의 조언은 스크롤하는 동안 셀 상태를 유지하는 것입니까, 아니면 앱이 종료 될 때도 "사용되었습니다"값을 유지해야합니까? (내가 한 변화가 그렇게하지 않았기 때문에). nsuserdefaults와 함께 사용해야합니까? 지금까지 아무 것도 시도하지 않았습니다.이 세 단계를 수행했습니다 : usedTransportIsSelected라는 데이터 객체에 bool 속성을 추가하고 제스처 인식기의 코드에 값을 설정 한 다음 cellforRowatindexpath에서 뷰를 설정합니다. 그러나 지속되지 않습니다. 어떤 통찰력? – IWannaLearn

+0

가장 가능성이 높습니다. 최신 iOS 버전에서는 사용자가 언제든지 백그라운드로 앱을 바꿀 수 있으며 시스템이 백그라운드에서 조용히 종료 할 수 있습니다. 백그라운드로 이동할 때 알림을 받으면 그때까지 앱 상태를 저장하지 않아도됩니다 (빠르게 할 수있는 한). –

0

아래 주어진대로 수행해야합니다. transportImageTapped 메소드의 구현이 변경되었습니다. 코드가 테스트되지 않았으므로 사소한 오류가 발생할 수 있습니다. 이것이 도움이되는지 알려주십시오. NSMutableArray 만들기 NSMutableArray *가 선택되었음을 나타냅니다.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"mainCell"; 
TransportCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    cell = [[TransportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

Transport *transportData = [self.dataSource objectAtIndex:indexPath.row]; 
cell.nameLabel.text = transportData.name; 
cell.transportImageView.image = transportData.transportImage; 
if([selected containsObject:indexPath]) { 
    cell.grayedImageView.image = transportData.usedTransportImage; 
} else { 
    cell.grayedImageView.image = transportData.deSelectedTransportImage; 
} 

UITapGestureRecognizer *grayedImageTouched = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(transportImageTapped:)]; 
grayedImageTouched.numberOfTapsRequired = 1; 
[cell.grayedImageView addGestureRecognizer:grayedImageTouched]; 
cell.grayedImageView.userInteractionEnabled = YES; 


return cell; 
} 

-(void)transportImageTapped:(UIGestureRecognizer *)gesture 
{ 
CGPoint point= [gesture locationInView:self.tableView]; 
NSIndexPath *theIndexPath = [theTableView indexPathForRowAtPoint:point]; 

UIAlertController *transportAlert = [UIAlertController alertControllerWithTitle:@"Yes, it's true..." message:@"I have used this type of transport before." preferredStyle:UIAlertControllerStyleAlert]; 

[transportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){ 

    NSLog(@"cancel"); 

}]]; 

[transportAlert addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

    if(selected containsObject:theIndexPath) { 
     //Already selected - Remove the selection 
     [selected removeObject:theIndexPath]; 
    } else { 
     // Set the object as selected 
     [selected addObjetc:theIndexPath]; 
    } 

    NSLog(@"has taken this transport before"); 
    NSArray* indexArray = [NSArray arrayWithObjects:theIndexPath, nil]; 
    // Launch reload for the two index path 
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; 

}]]; 

[transportAlert addAction:[UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ 

    if(selected containsObject:theIndexPath) { 
     //Already selected - Remove the selection 
     [selected removeObject:theIndexPath]; 
    } else { 
     // Set the object as selected 
     [selected addObjetc:theIndexPath]; 
    } 

    NSLog(@"has not taken this transport before"); 
    NSArray* indexArray = [NSArray arrayWithObjects:theIndexPath, nil]; 
    // Launch reload for the two index path 
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; 

}]]; 

[self presentViewController:transportAlert animated:YES completion:nil]; 

} "예"를 클릭하면

+0

@ArunGupta ... 고맙습니다. 그것은 유망 해 보였고 나는 그것을 시도했지만 alertview를 추가했을 때해야 할 이상한 논리가 작동하지 않게되었다고 믿는다. (이미지는 선택에 따라 변하지 않는다). 나는 내가 그것을 얻을 수 있는지보기 위해 그것을 뒤범벅 할 것이다. – IWannaLearn

+0

cellForRowAtIndexPath에서 변경 한 내용을 확인 했습니까? 무슨 문제가 있습니까? –

+0

@Arun ... "선택자 'indexPathForRowAtPoint'에 대해 알려진 클래스 메소드가 없습니다. '라는 오류가 발생합니다." – IWannaLearn

관련 문제