美文网首页
NSNotificationCenter

NSNotificationCenter

作者: nalis风 | 来源:发表于2016-07-20 21:15 被阅读5次

    注册页面---------------

    //在通知中心注册通知

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(receive:)name:@"receive"object:nil];

    [play.btnaddTarget:selfaction:@selector(playMusic)forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.

    }

    -(void)receive:(NSNotification*)noti

    {

    play.btn.selected=NO;

    dic= noti.object;

    NSString*path = [[NSBundlemainBundle]pathForResource:[dicobjectForKey:@"name"]ofType:@"mp3"];

    NSURL*url = [NSURLfileURLWithPath:path];

    play1= [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];

    play.current.text=[selfchangeTime:play1.currentTime];

    play.duration.text= [selfchangeTime:play1.duration];

    self.navigationItem.title= [dicobjectForKey:@"name"];

    }

    使用界面-----------

    //给消息中心发通知

    [[NSNotificationCenterdefaultCenter]postNotificationName:@"receive"object:[arrobjectAtIndex:indexPath.row]];

    相关文章

      网友评论

          本文标题:NSNotificationCenter

          本文链接:https://www.haomeiwen.com/subject/uzavjttx.html