objective c - NSPageController tutorial for Cocoa on OS X -
i need utilize nspagecontroller
in project have no thought how works, have time simple tutorial show me because documentation isn't helping me.
forgot mention: i'm working on mac project
(not ios
)
simple nspagecontroller book mode tutorial
create new cocoa application-project. open mainmenu.xib
in interface builder , add together image well , label objects application window. add together page controller object.
set page controller's view point image well.
add imagesimages.xcassets
i used 3 images in sample project:
first.png second.png third.png myappdelegate.hadd referencing outlets page controller, label , image well. set myappdelegate
nspagecontrollerdelegate
, add together nsarray
images. after myappdelegate.h
file should this:
@interface myappdelegate : nsobject <nsapplicationdelegate, nspagecontrollerdelegate> @property (assign) iboutlet nswindow *window; @property (unsafe_unretained) iboutlet nspagecontroller *pagecontroller; @property (weak) iboutlet nsimageview *imageview; @property (weak) iboutlet nstextfield *infolabel; @property (nonatomic) nsarray *imagearray; @end
myappdelegate.m some initialization:
- (void)awakefromnib { _imagearray = @[ [nsimage imagenamed:@"first"], [nsimage imagenamed:@"second"], [nsimage imagenamed:@"third"]]; /* set delegate nspagecontrol */ [_pagecontroller setdelegate:self]; /* set arranged objects nspagecontrol */ [_pagecontroller setarrangedobjects:_imagearray]; /* set transition style, in illustration utilize book style */ [_pagecontroller settransitionstyle:nspagecontrollertransitionstylestackbook]; /* set info label's text */ nsstring *info = [nsstring stringwithformat:@"image %ld/%ld", ([_pagecontroller selectedindex]+1), [_imagearray count]]; [_infolabel setstringvalue:info]; }
page controller delegate methods:
- (void)pagecontroller:(nspagecontroller *)pagecontroller didtransitiontoobject:(id)object { /* when image changed, update info label's text */ nsstring *info = [nsstring stringwithformat:@"image %ld/%ld", ([_pagecontroller selectedindex]+1), [_imagearray count]]; [_infolabel setstringvalue:info]; } - (nsstring *)pagecontroller:(nspagecontroller *)pagecontroller identifierforobject:(id)object { /* returns object's array index identiefier */ nsstring *identifier = [[nsnumber numberwithinteger:[_imagearray indexofobject:object]] stringvalue]; homecoming identifier; } - (nsviewcontroller *)pagecontroller:(nspagecontroller *)pagecontroller viewcontrollerforidentifier:(nsstring *)identifier { /* create new view controller , image view */ nsviewcontroller *vcontroller = [nsviewcontroller new]; nsimageview *iview = [[nsimageview alloc] initwithframe:[_imageview frame]]; /* image image array using identiefier , set image view */ [iview setimage:(nsimage *)[_imagearray objectatindex:[identifier integervalue]]]; /* set image view's frame style none */ [iview setimageframestyle:nsimageframenone]; /* add together image view view controller , homecoming view controller */ [vcontroller setview:iview]; homecoming vcontroller; }
and it's done if _pagecontroller null/nil
connect page controller _pagecontroller pressing ctrl
, dragging mouse _pagecontroller in myappdelegate.h
file.
objective-c osx cocoa
Big Thanks for this wonderful read. I enjoyed every little bit of reading and I have bookmarked your website to check out new stuff of your blog a must read blog.
ReplyDeleteios training institute in chennai
ios developer training in chennai