Simple use of notifications
Last Update:2014-08-02
Source: Internet
Author: User
// Send a notification
Nsnotification * updatenotifi = [nsnotification notificationwithname: icationication_name_update_push object: Nil];
[[Nsicationcenter center defacenter center] postnotification: updatenotifi]; [nsicationicationcenter defacenter center] addobserver: Self selector: @ selector (addfavwork) Name: @ "add_stylist_work" Object: Nil];-(void) addfavwork {
// Add to Favorites If no favorites is available
Appstatus * As = [appstatus sharedinstance];
If ([as. User hasaddfavwork: Self. Work. ID]) {
Self. collectimage. Image = hasaddwork;
} Else {
Isoperatework = yes;
[[Userstore sharedstore] addfavwork: ^ (nserror * ERR ){
If (ERR = nil ){
[[Stylistworkstore sharedstore] getstylistworklist: ^ (page * Page, nserror * ERR ){
Isoperatework = no;
[Svprogresshud showsuccesswithstatus: @ "added to favorites! "Duration: 1.0];
Self. collectimage. Image = hasaddwork;
Self. numofcollect. Text = [nsstring stringwithformat: @ "% d users have added this file to Favorites", ++ self. Work. collectedcount];
[[Nsicationcenter center defacenter center] postnotificationname: @ "operate_work" Object: Nil];
[Mobclick event: log_event_name_add_fav_work attributes: [nsdictionary dictionarywithobjectsandkeys: @ (self. Work. Stylist. ID), @ "", nil];
} URL: As. User. idstr Refresh: Yes];
} Else {
[Svprogresshud showerrorwithstatus: @ "failed to add to favorites. Please try again later! "Duration: 1.0];
Isoperatework = no;
}
} Userid: As. User. idstr workid: Self. Work. ID];
Nsdictionary * dict = [nsdictionary dictionarywithobjectsandkeys: @ (self. Work. ID), @ "work ID", nil];
[Mobclick event: log_event_name_add_fav_work attributes: dict];
}
}
-(Void) scrollviewdidscroll :( uiscrollview *) scrollview
{
[Self drivescrollview: scrollview lastoffsety: lastoffsety scrollviewheight: scrollviewheight topview: Self. header];
Lastoffsety = scrollview. contentoffset. Y;
}
-(Void) drivescrollview :( uiscrollview *) scrollview lastoffsety :( float) _ lastoffsety scrollviewheight :( float) _ scrollviewheight topview :( uiview *) view {
If (scrollview. contentoffset. y> 0 & scrollview. contentoffset. Y <(scrollview. contentsize. height-scrollview. frame. size. height) & scrollview. contentsize. height> (view. frame. size. height + _ scrollviewheight + general_margin )){
If (_ lastoffsety-scrollview. contentoffset. Y> 0 & _ lastoffsety <(scrollview. contentsize. Height-scrollview. Frame. Size. Height) {// drop-down
If (view. Frame. Origin. y! = 0 ){
[Uiview animatewithduration: 0.5 animations: ^ {
View. Frame = cgrectmake (0, 0, screen_width, view. Frame. Size. Height );
Scrollview. Frame = cgrectmake (0, view. Frame. Size. Height, screen_width, _ scrollviewheight );
}];
}
} Else if (_ lastoffsety-scrollview. contentoffset. Y <0) {// push up
If (view. Frame. Origin. y! =-View. Frame. Size. Height ){
[Uiview animatewithduration: 0.5 animations: ^ {
View. Frame = cgrectmake (0,-view. Frame. Size. Height-splite_line_height, screen_width, view. Frame. Size. Height );
Scrollview. Frame = cgrectmake (0, 0, screen_width, _ scrollviewheight + view. Frame. Size. Height );
}];
}
}
}
}