2014-02-05 1 views
0

UIActionSheet에는 터치 된 배열을 즐겨 찾기로 표시하는 버튼이 있습니다. 배열이 가장 좋아 할 때 배열 이름 앞에 별표가 표시됩니다. 즐겨 찾기 아이콘에는 알파 0이 있고 "즐겨 찾기에 추가"단추를 누르면 알파가 1로 변경됩니다. 배열은 각 셀에 1 개의 배열을 표시하는 UIViewController 안에 있습니다.UIIctionView의 UIIctionSheet에서 알파와 쇼 변경하기

내가보기에 별이 표시되도록 ViewController를 다시 열어야한다는 문제가 있습니다.

ViewController를 다시 열지 않고도 "즐겨 찾기에 추가"버튼을 누르면 즉시 별표가 표시되도록 수정할 수 있습니까?

에 즐겨 찾기 아이콘 알파 아래에 업데이트됩니다

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 

그리고 이것은 알파를 업데이트하는 코드입니다 :

if ([FavoriteArray containsObject: [mainArray objectAtIndex:indexPath.row]]) 
     { 
      favoriteImage.alpha = 1; 

     } 

감사합니다!

+1

좋아하는 아이콘을 어디에서 업데이트하고 있습니까? 코드를 게시 할 수 있습니까? – 68cherries

+0

@ 67cherries 코드가 추가되었습니다. – ThomasGulli

답변

1

작업 시트가 적용된 시점을 모니터링하고 그에 따라 컬렉션 뷰를 업데이트해야합니다.

UIActionSheet* actionSheet = ...; 

// Set yourself as the action sheet delegate, so you can monitor when events occur 
actionSheet.delegate = self; 

... 

// This is called when a user selects an item within the action sheet 
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    // kFavouriteButtonIndex is the index of the action sheet item to favourite 
    if (buttonIndex == kFavouriteButtonIndex) { 
     // Reload your collection view to update the cells 
     [self.collectionView reloadData]; 
    } 
} 

을 대신 reloadData를 호출하면 favourited되고있는 항목의 indexPath를 알고 있다면 다음 과정을보다 효율적으로 할 수 reloadItemsAtIndexPaths:@[indexPath]를 호출 할 수 있습니다, 다음과 같이 예제 구현입니다.

0

버튼을 선택하면 이미지의 알파를 업데이트하려고합니다. UIViewController에 UIActionSheetDelegate 프로토콜을 구현하여이 작업을 수행 할 수 있습니다.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    //make sure that the button pressed is the one which should change the image alpha: 
    if(buttonIndex == 2){ //put the button index in the place of "3"  

    //your code to update the alpha here 
    } 
} 

것은 당신이 자기에 UIActionSheet의 대리자를 설정 있는지 확인하십시오

@interface MyViewController : UIViewController <UIActionSheetDelegate> 

이 나서하는 .m 파일에 actionSheet:clickedButtonAtIndex: 메소드를 오버라이드 (override) : 당신은 당신의보기 컨트롤러의하는 .m 파일을이 작업을 수행 할 수 있습니다

myActionSheet.delegate = self;