Phunzirani kukonza masewera a iOS: kudziwa Xcode (II)

Phunzirani pulogalamu

Pambuyo pamagawo omaliza, otchedwa phunzirani kupanga mapulogalamu a iOS: Kudziwa Xcode, ndipo tisanalowe mu Cocos2d, tiyeni tisunthire pang'ono ku Xcode. Pamwambowu, tizilumikizana ndi zomwe zidapangidwa, m'malo mongodzichepetsera ku "Hello world" yosavuta.

Ndi izi, mupeza luso pakusamalira Xcode, ndipo mudzatha kupanga mapulogalamu anu oyamba "othandiza" mwachangu; pophunzira momwe mabatani amagwiritsidwira ntchito ndi zolemba. Popeza kalasi iyi ndi yovuta kwambiri kuposa yapita, mudzakhala ndi zitsanzo zothandiza kutsitsa kumapeto kwa positi, kuti muthe kuyendetsa ndikuwona ngati ikugwira bwino ntchito!

Choyamba, timatsegula Xcode ndikupanga projekiti yatsopano posankha template ya "single view application", monganso m'mbuyomu; Izi zikhazikitsa malo ogwiritsira ntchito zenera limodzi, ndi «graphic Assistant». Tikatsegula, timasankha fayilo viewcontroller.xib (Kumbukirani kuti ndi "mawonekedwe owonekera" omwe timawona kapena kuwonera koyamba, kotchedwa viewcontroller, ndipo gawo lake la "code" lili m'mafayilo chiwonetsedwe.m y chiwonetsero.h), ndipo timapita ku bokosi lazinthu, lomwe lili kumanja kumanja, kuti tiyambe kukokera zigawo zathu: zolemba, mabatani ... zidzakhala ndi zonse!

Kuyika zinthu mu xcode

Monga tikuwonera pachithunzichi, nthawi ino takoka zotsatirazi:

  • Chinthu "chizindikiro«, Pogwiritsa ntchito mutu. Sichingagwirizane ndi chilichonse.
  • Chinthu china «chizindikiro«, Zomwe zikhala ndi manambala.
  • A «stepper«, Woyang'anira kukulitsa kapena kutsitsa kuchuluka kwamanambala am'mbuyomu« chizindikiro ».
  • Un batani kuwunika kuti "chizindikirocho" chikufanana ndi mtengo womwe tidasankha kale.

Kodi mukudziwa kale tanthauzo la ntchitoyi? Zosavuta kwambiri; Tiyenera kusankha zaka zathu (chaka ndi chaka ndi «stepper»), kenako, pogwiritsa ntchito batani, onani ngati tili azaka zovomerezeka. Zopanda tanthauzo komanso zophunzitsira, ndi zochitikazi muphunzira kuchokera ku kupweteka kwa cholembera zinthu zingapo.

Makonda anu mu xcode

Monga mukuwonera pachithunzichi pamwambapa, kukula ndi mtundu wa «chizindikiro» zitha kukhala Sinthani. Chilichonse chimakhala ndi magawo ambiri omwe mungapeze ngati mungafufuze pang'ono. Mukasiya chinthu chilichonse ndi mawonekedwe omwe mumakonda kwambiri, ndi nthawi yoti muwerenge: popeza tsopano tili ndi «kukopedwa»Kugwiritsa ntchito kwathu; palibe chomwe chimagwirizana ndi chilichonse ... tiyenera kuchipangira umodzi.

Kuti tichite izi, tiziwononga ndi ena code (zofunikira kwambiri, komanso zofotokozera); makamaka ndi fayilo chiwonetsero.h, yomwe imakhala ndimatanthauzidwe ofunikira owonera (zenera lathu lalikulu!). Sichichita malamulo kapena zochita, imangokhazikitsa maziko ndi ntchito zofunikira, kotero kuti chiwonetsedwe.m Titha kuzigwiritsa ntchito ndikugwira ntchito molimbika ... zomwe tiziwona zikuwonetsedwa viewcontroller.xib! Mbali zonse zitatu za ndalama imodzi.

Izi zikadafotokozedwa, titha kuyamba kufotokoza mu "code" zinthu zonse zomwe tazifotokoza bwino. Timapita kumalo osungira zakale chiwonetsero.h, ndipo timawonjezera izi:

kukhazikitsa zosintha mu xcode

Pali njira zingapo zofotokozera zosintha kapena zinthu, koma pakadali pano, popeza tikufuna chinthu choti tipeze izi (zenera lathu, gawo lazithunzi), timazipereka motere (kuyambira ndi @ katundu). Umenewu ndi mutu womwe tikambirana m'makalasi amtsogolo, chifukwa pano ndikofunikira kudziwa zomwe aliyense akunena kapena kuzindikira: a «chizindikiro»(Mmodzi yekha, popeza mutu womwe timapanga sungagwirizane ndi chilichonse, ndipo sitifunikira kutanthauzira mu code), chosinthika chotchedwa«Zaka Zambiri»(Ichi ndi chatsopano, sitinachiyike pagawo lachiwonetsero .. chingosunga zaka zakubadwa kuti zifanane), a«stepper»(Wotchedwa stepper1).

Kuphatikiza pamwambapa, palinso ntchito ziwiri (ziwiri zomwe zimayamba ndi chinyengo ndi ntchito); m'modzi mwa iwo adzakhala ndiudindo wochita kena kake tikakanikiza sitepeyo (Mwachitsanzo, kupanga "chizindikiro" kusintha zaka zathu? enieni), ndi wina woyang'anira kuyerekezera zaka zamakono za chizindikirocho ndi zomwe takhazikitsa.

Pakadali pano tili ndi gawo lachiwonetsero, komanso gawo la code. Komabe, timaphunzitsa bwanji kugwiritsa ntchito kwathu komwe mtundu uliwonse wa kakhodi umafanana, ndi kufanana kwake mu gawo lazithunzi? Zosavuta kwambiri. Timadina viewcontroller.xib, ndipo timadina batani loyera mozungulira lomwe lili ndi mawonekedwe a «kusewera» ndi mawu akuti «chiwonetsero cha chikalata», chomwe timapeza kumanzere kumanzere kwa pepala loloza. Ndi izi, gulu lomwe lili ndi zenera lidzawonetsedwa.

Tikuwona "Okhazikitsa malo" pamwambapa, omwe ali ndi ma cubes awiri: wachikaso (Fayilo mwini wake), ndipomwe timayanjanitsa zinthuzo ndi zilembo (zolemba, mabatani, ndi zina); ndi lina lofiira (First Responder), pomwe tidzagwirizanitsa ntchito zomwe tazifotokozera kuzinthu zosiyanasiyana (mwachitsanzo, podina batani ntchito ikuchitika).

Mndandanda wa mndandanda wa Xcode

Timayamba ndi zinthuzo. Dinani pomwepo pa cube ya «Files Owner», ndipo mndandanda wakuda udzawonetsedwa. Tikuwonetsa gawo la "Malo ogulitsira", ndipo tiwona zonse zomwe tazifotokoza mu code (pali ziwiri zokha, label ndi stepper1); Tiyenera kuwakokera kuzithunzi zawo: chizindikiro ndi zilembo zomwe tidapanga, ndi chopondera1 ndi stepper.

Tikakoka, tiwona momwe "buluu lozungulira" limapangidwira lomwe limatsata mbewa yathu ku chinthu chomwe tikufuna kuyanjana nacho. (Chidziwitso: kuti muyambe kukoka, muyenera kudina mabwalo opanda kanthu pafupi ndi dzina la chinthu chilichonse, monga chithunzi)

Kuphatikiza zinthu mu xcode

Tsopano muyenera kuchita chimodzimodzi ndi ntchito; Dinani pomwepo pa «Choyamba Kuyankha», ndipo timachita izi:

  1. Timadina pa «checkAge», ndipo osamasula, timakoka mpaka batani lawindo lathu lowoneka bwino, lomwe limafufuza zaka. Mndandanda watsopano wotsitsa umatsegulidwa ndipo timasankha «Gwiritsani pansi».
  2. Timachitanso chimodzimodzi ndi "stepperValueChanged", koma nthawi ino timakokera ku "stepper" yathu, ndipo pazosankha timasankha "Value Changed".

Kuphatikiza zochita mu xcode

Pakadali pano zomwe zatsala ndikuwonjezera "nambala yeniyeni" ku chiwonetsedwe.m; Tiyenera kukuwuzani choti muchite ndi chilichonse chomwe chikuchitika. Timayamba ndikukuwuzani kuti muzindikire zosintha zomwe zafotokozedwera chiwonetsero.h (zaka zosinthika mwalamulo, stepper kusinthasintha, ndi chizindikiro chosinthika; zonsezi zimalumikizidwa ndi mnzake wojambula) pogwiritsa ntchito «@synthesize variable_name_u_element«, Monga momwe tikuwonera pachithunzichi:

Kukhazikitsa zosintha mu xcode

Popanda kuchoka chiwonetsedwe.m, tinapita ku ntchitoyi viewDidLoad (kumapeto kwa fayilo), ndi pansipa zomwe zalembedwa kale, koma «}«, Timatanthauzira zaka zakubadwa zomwe ziyenera kukhala m'dziko lathu. Poterepa, 18:

Xcode idachita ntchito

Pomaliza, tipanga ndikukonzekera pulogalamu ya ntchito zomwe tafotokozera mu viewcontroller.h (pali awiri okha). Mmodzi adzaphedwa nthawi zonse tikakanikiza stepper, ndipo ziyenera kuwonetsa zaka zomwe zikusintha, mu «chizindikiro» chathu.

Wina adzaphedwa tikakanikiza batani cheke zaka" ngati sichoncho, chifiira. Zonse ziwiri ziyenera kuyikidwa mu fayilo chiwonetsedwe.m; Mwachitsanzo, nthawi yomweyo ntchitoyi isanachitike - (opanda) viewDidLoad.

ntchito ziwiri

Tsopano pakubwera zabwino kwambiri. Muyenera kuyesa! Pitani ku batani lakusewera pamwambapa, kuti muwone ngati "Simulator ya iPhone" yasankhidwa, ndikumenya. Zenera lanu lidzatsegulidwa, ndipo mutha kulumikizana nalo!

chithunzi cha masewera olimbitsa thupi awiri

Ntchitoyi itha kupangika kukhala yovuta kwambiri, koma ndi izi muli ndi maziko oti mufufuze nokha, ndikuyesanso zosankha zina. Kuti musavutike kutsatira phunziroli, chifukwa chongofuna kudziwa, kapena ngati mungalephere kugwira ntchito, nayi ntchitoyi mu Archive kupanikizika! Ndikukhulupirira zakuthandizirani ... mpaka nthawi ina!

Zambiri - Phunzirani pulogalamu: kudziwa Xcode (I)

Tsitsani - Kalasi yachiwiri yamapulogalamu a Xcode


Zomwe zili m'nkhaniyi zikutsatira mfundo zathu za malamulo okonzekera. Kuti mufotokoze cholakwika dinani Apa.

Ndemanga za 7, siyani anu

Siyani ndemanga yanu

Anu email sati lofalitsidwa. Amafuna minda amalembedwa ndi *

*

*

  1. Wotsogolera pazosankhazi: Miguel Ángel Gatón
  2. Cholinga cha deta: Control SPAM, kasamalidwe ka ndemanga.
  3. Kukhazikitsa: Kuvomereza kwanu
  4. Kulumikizana kwa zomwe zafotokozedwazo: Zomwezo siziziwululidwa kwa anthu ena kupatula pakukakamizidwa mwalamulo.
  5. Zosunga: Zosungidwa ndi Occentus Networks (EU)
  6. Ufulu: Nthawi iliyonse mutha kuchepetsa, kuchira ndikuchotsa zidziwitso zanu.

  1.   Ophwanya anati

    Zangwiro, ndikuyembekeza kuti simuchedwa ndikufalitsa maphunziro ambiri. Koma mutha kufotokoza mwatsatanetsatane momwe ntchito iliyonse imagwirira ntchito, mwachitsanzo: "*) sender" ndi "Osankhidwa:% d" popeza pali anthu omwe alibe chidziwitso cha cholinga-c. Zolemba zabwino kwambiri.

    Moni Sergio Abril.

    1.    Sergio Epulo anati

      Hello!
      Zikomo kwambiri, ndikulongosolerani mwachidule, "mwachangu" komanso "mosavuta", chifukwa ndi funso lothandiza kwambiri:

      Nthawi zambiri mukamasulira ntchito, mumayenera kuwonjezera magawo omwe mukufuna kutumiza ku ntchitoyi, komanso momwe mungafunire ntchito; Pankhani ya mabatani ndi opondera, timawawonjezera kuti ntchitoyi idziwe kuti ikuyitanitsa chinthu china (ngati UIButton, china, UIStepper), pomwe timayika dzinalo tikufuna kugwira ntchito ndi mkati mwa ntchitoyi (pankhaniyi onse «sender», koma aliyense amagwira ntchito). Chifukwa chake, pambuyo pa dzina la ntchitoyi, pali colon, kenako (UIButton *) Sender.

      Kuti ndikuwonetseni kuti ntchitozi zikulandila "chinthu chomwe chimazitcha", ngakhale zili zoona kuti sindinagwiritse ntchito mwayiwu, yesani izi:

      Sinthani ntchito ya checkerValuechanged function (mkati mwa viewcontroller.m), "stepper1" yonse yomwe mungapeze, ndi "sender". Mudzawona kuti ikupitilizabe kugwira ntchito chimodzimodzi, ndipo zotsatira zake ndizofanana (ngakhale zili choncho, sindinagwiritse ntchito mwayi womwe "sender" amalandira ndikusunga, koma ndalongosola za stepper1 (zomwe zili zomwezo) ... chifukwa chake kukayika kumabuka .. kufunsa bwino!

      Ponena za chachiwiri, NSLog sichinthu china koma chophimba "log", kotero kuti mawu omwe timayika pakati pamakalata ogwiritsira ntchito awonekere pansipa pa Xcode console. Ngati, kuwonjezera apo, tikufuna kuti iwonetse zofunikira zina, kuti tiwone, mwachitsanzo, phindu la stepper1 nthawi zonse, ndiyo njira yolondola yowonjezeramo; kuyika komwe tikufuna kuti phindu lipite% d, ndipo pambuyo polemba mawuwo, dzina la zosinthazo. (% d amatanthauza kuti ndi nkhokwe yochuluka kwambiri. Mwachitsanzo, zikadakhala kuti, decimal, mukadayenera kuyika% f).

      Nthawi ina mungaganize kuti tiyenera kuyika NSLog (@ "yosankhidwa: YOSIYANA");:% d ", VARIABLE), kotero kuti tikazindikira"% "tidziwe kuti pali phindu lomwe tiziika pambuyo pa koma .

      Ndizosokoneza pang'ono, koma ndikhulupilira kuti ndadzifotokozera ndekha 😉

      1.    Adnn anati

        Zikomo chifukwa cha kuwolowa manja kwanu; pitilizani 🙂

  2.   Alireza anati

    Chonde osasiya kupanga uthengawu, ndiwothandiza kwambiri ndipo anthu ambiri, kuphatikiza inenso, ndimakonda.

  3.   Gustavo de la Rosa anati

    Nkhani ziwiri zomwe muli nazo mpaka pano ndizabwino kwambiri. Funso limodzi, chifukwa ntchito zomwe zidagwiritsidwa ntchito ndi za mtundu wa IBAction osati chabe?

  4.   VicT04- anati

    Simunakonzepo chilichonse ndipo mumapanga chilichonse kukhala chophweka Zikomo kwambiri polemba izi ndikuyembekezera zina, pepani koma mabuku ena kapena masamba ena kuti mupitilize kuphunzira nkhaniyi ndikufuna kudziwa momwe angagwiritsire ntchito zilibe kanthu ngati ali mchingerezi ndikukhulupirira mutha kundithandiza zikomo.

  5.   Llusan anati

    Kodi padzakhala gawo lachitatu? Tili kale mu Marichi