網頁

2012年7月30日 星期一

didSelectRowAtIndexPath indexPath

點選cell時 僅僅該cell變色 其他cell正常
 

@interface Vocabulary : UIViewController
{
    int currIndex;
    int currSec;
}

@property (nonatomic, assign) int currSec;
@property (nonatomic, assign) int currIndex;
 

@synthesize currIndex, currSec;

//當選選擇時 一律變黑 記錄當時indexPath 再進入播放變紅(為所選的)結束變黑(為所記錄的)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.

    [self performSelector:@selector(endOfPlay)];
    currSec = indexPath.section;
    currIndex = indexPath.row;
        
    [self playSound: indexPath];
}
//停止播放為黑
- (void) endOfPlay
{

    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:currIndex inSection:currSec];
    
    UITableViewCell *cell = [self.mainTableView cellForRowAtIndexPath: indexPath];
    [self setAccessoryViewForCell: &cell fileName: @"black.png"];
}

#pragma mark -
#pragma mark Sound

//播放為紅
- (void) playSound: (NSIndexPath *)indexPath
{
    [avPlayer play];
    
    
    UITableViewCell *cell = [self.mainTableView cellForRowAtIndexPath: indexPath];
    [self setAccessoryViewForCell: &cell fileName: @"red.png"];

}

#pragma mark -
#pragma mark AVAudioPlayer delegate

- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *)aPlayer successfully: (BOOL)flag
{
    if (flag == YES) {
        
        NSLog(@"===audioPlayerDidFinishPlaying===");
        
        [self endOfPlay];
 
    } 
    
}

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。