Ke hoʻomohala ma iPhone (5): kā mākou noi mua (III)

En kā mākou ʻatikala i hala ua hoʻokomo mākou i kahi Label, kahi TextField a me kahi Pihi ma ke kikowaena o kā mākou noi. Makemake mākou e hoʻohou i ka ʻike o ka Label me ka mea i hoʻokomo ʻia i ka TextField ke kaomi ʻana i ka Pihi. Ua hana mākou (ʻanuʻu 1) i ka papahana, a (ʻanuʻu 2) i hoʻohana iā InterfaceBuilder e wehewehe i ka pale. I kēia manawa e hoʻomau mākou me ke koena o nā ʻanuʻu e haʻalele i ka noi ʻana.

KaʻAnuʻu 3. Hana i nā loli i ka ViewController.

Loaʻa iā mākou kā mākou interface pono. I ka ʻoiaʻiʻo, inā mākou i kūkulu iā Build & Go hiki iā mākou ke ʻike pehea mākou e hana nei:

Akā maopopo leʻa ʻaʻohe mea e hana ke kaomi ana i ka pihi, no ka mea ʻaʻole mākou i hana i ka mea liʻiliʻi e pono ai. Ma kēia ʻanuʻu 3 e hoʻolauna mākou i nā loli a me nā kiʻina hana i ka HelloWorldViewController, ma ke kikowaena (.h faila) a me ka hoʻokomo (.m faila). E hana i kēia, e like me kā mākou i hōʻike ai i ka hopena o ka pou i hala, pono mākou e ʻike e pili ana ka TextField i kahi papa UITextField, a me ka Label i kahi papa UILabel. Aia kēia mau papa 2 ma loko o ka papahana UIKit.

Inā ʻaʻole mākou i pani a hoʻopakele i ka Interface Builder, hana mākou ia a ma XCode wehe mākou i ka faila HelloWorldViewController.h. E loaʻa i ke code i kēia manawa e like me kēia:

Ke nānā nei mākou i kekahi Pahuhopu-C. Ma kēia pāʻālua ʻike mākou i kahi hoʻolaha hoʻokomo o ka waihona UIKit, kahi o ka papa UILabel a me UITextField. ʻIke mākou i ka hoʻolaha ʻana o ka interface, a hoʻolōʻihi ʻia ia mai ka UIViewController generic o UIKit.

Ma loko o ka code interface ua hoʻokomo mākou i kēia code:

Hiki iā mākou ke wehewehe i ka hana a mākou i hana ai:

  • Ua hoʻolaha mākou i loko o ka @interface block 2 mau ʻano o ka ʻano UILabel a me UITextField, me 2 mau inoa ʻano loli * a me * textField pākahi. ʻIke ʻia ʻo IBOutlet. He aha kēia mea a pau? Wehewehe mākou iā mākou iho. ʻAʻole he ʻano loli ʻo IBOutlet; he kuhikuhi e kōkua i ka Interface Builder e ʻike i ke ola o kēia mau loli o ka ʻano UILabel a me UITextField. Ma ke ala, e hoʻomanaʻo ma ka ʻatikala i hala aku nei ua hāʻawi mākou iā ʻoe i kahi maʻalea e ʻike ai i nā ʻano loli o nā mea kaohi (pihi, lepili, kahua kikokiko, a pēlā aku) i ka Interface Builder. Ma ka ʻaoʻao ʻē aʻe, hoʻopūʻiwa paha ka hoʻopuka o * i mua o ka inoa loli i nā polokalamu ʻo Java, ʻaʻole nui ʻo C ... akā e aʻo ʻoe pēlā ʻoe e kākau ai i nā loli instance i Objective-C.
  • Hōʻike ʻia nā waiwai UILabel a me UITextField. nonatomic a hoʻopaʻa mākou ʻaʻole mākou e ʻike i kēia manawa, pili i ka mālama hoʻomanaʻo.
  • ʻIke mākou e hoʻolaha mākou i kahi hana, updateText. He - hōʻailona i mua o ia, e hōʻike ana he ʻano hana ia, ʻaʻole he ʻano papa (wehewehe ʻia kahi hōʻailona + no lākou). ʻAʻole hiki iā mākou ke wehewehe i kēia no ka mea ʻo ia ka papahana hoʻonohonoho pono i nā mea ... ʻaʻole hoʻihoʻi kēlā ʻano i kekahi mea (ʻo ia hoʻi, hakahaka) a loaʻa i kahi palena o ka id type. ʻO ke kumu e pili ana i ka mea e ʻike ai i ka mea e hoʻokau i kā mākou kāhea iā mākou updateTexto, ka mea e hoʻohou i ka waiwai o ka lepili. Hiki iā mākou ke koho mai ʻo ka kaomi ke pihi iā ia iho ...

Ke pau kēia, pau mākou me ka ʻanuʻu 3.


KaʻAnuʻu 4. Hoʻopili i nā kāohi View i nā hoʻololi Controller.

Inā mākou e loiloi, ma kekahi ʻaoʻao ua hoʻomohala mākou i kā mākou interface me Interface Builder, a ma kekahi ʻē aʻe i loaʻa iā mākou nā loli e pili ana i kēlā mau kaohi i ka HelloWorldViewController.h (interface of the HelloWorldViewController.m control class). Eia nō naʻe, ʻaʻohe pilina ma waena o ka ʻike a me ka mea hoʻokele, ʻo ia hoʻi, ʻaʻole mākou i hāʻawi i kekahi mau ʻōkuhi e pili ai, no ka laʻana, ka papa huaʻōlelo a mākou e hoʻolālā ai i ka Interface Builder me ka loli o ka ʻano UITextField a mākou i hoʻokomo ai i ka papa. I kēia manawa e hana ana mākou i kēia hana. Wehe hou mākou i ka Interface Builder ma ke kaomi ʻana iā HelloWorldViewController.xib, kaomi ma ka pahu ʻōlelo, a ma ka palette Luna Nana hele mākou i ka ʻaoʻao ʻelua (Text Field Connections). ʻIke mākou aia kekahi ʻāpana i kapa ʻia ʻo Referencing Outlets, me ka ʻole o kekahi mea i kaha ʻia. ʻO ia ka mea i kēia manawa ʻaʻole ʻike ka mea kūkulu Interface i kekahi pilina ma waena o kēia kahua kikokiko a me kahi IBOutlet (Interface Builder Outlet) o kahi papa ... akā he UITextField IBOutlet kā mākou i loko o kā mākou HelloWorldViewController, no laila e hoʻopili mākou iā ia.

E hana i kēia, e like me kā mākou e ʻike nei i ke kiʻi, ma ke kaomi ʻana i ka pōʻai liʻiliʻi e pili ana i «New Referencing Outlet», kauō mākou i ka Mea Kānāwai o ka puka aniani i kapa ʻia HelloWorldViewController.xib. E ʻae iā mākou e koho i nā koho 2, e nānā (i ka ʻike piha) a me textField (kā mākou loli). ʻIke maoli mākou e koho iā textField, a pēlā mākou e pili ai i kā mākou pahu kikoʻī i ka loli o kāna ʻano UITextField. Ma ke ala, ʻo ka Fail'sOwner a mea ʻona paha o ka faila ʻaʻole i ʻoi aku a emi paha ma mua o kā mākou papa hoʻokele ...

Hoʻomaʻa hou mākou i ka hana me ka lepili, e pili ana i kā mākou lepili loli. A me ke pihi, he mea ʻokoʻa ia. I kēia hihia e hoʻopili mākou iā ia i kā mākou updateTexto hana, akā no kahi hanana kikoʻī. Hana i kēia me ka hanana 'Touch Up Inside', a koho i kā mākou hōʻanoTexto hana:

A ma kēia ʻano ua pili mākou i nā kaohi a mākou i wehewehe ai me Interface Builder a me nā loli a mākou i hoʻokomo ai i ka mea hoʻokele. Hoʻopau mākou i ka Interface Builder e mālama nei i nā mea āpau a hele mākou i ka anuu hope loa e hoʻi nei i XCode.

KaʻAnuʻu 5. Nā hanana hou.

Ma XCode wehe mākou i ka HelloWorldViewController.my a kau mākou i ke code aʻe i like ai kā mākou papa me kēia:

Inā mākou e nānā pono ua kau maʻalahi i ka palaka @synthesize, a me ka hoʻokō ʻana o ka hana i haʻi ʻia ma ka interface .h, updateTexto. Ma lalo o kēlā code e loaʻa iā ʻoe ka nui o nā pāʻālua ʻōlelo.

Hana ka laina @synthesize i kekahi mea e like me ka hana ʻana i ka getter / setter (accessors / mutators) maʻamau i nā ʻōlelo OO (encapsulation). Pono mākou iā lākou i hiki i ka ʻike i ka mea hoʻoponopono, no ka laʻana, o ka pahu ʻōlelo.

ʻO ka hana updateTexto, e like me kāu e ʻike ai, hoʻomaikaʻi wale i ka huaʻōlelo o kā mākou lepili me ka ʻike o ka kahua kikokiko. Pau mākou.

I kēia manawa, hana maʻalahi mākou iā Build & Go, a e ʻike ʻoe i ka wā e hoʻokomo ai i kahi aho kikokiko a kaomi ma ka pihi, hoʻomaikaʻi ʻia ka ʻike o ka lepili. Ma ka ʻatikala aʻe e hoʻolauna mākou i kā mākou noi.


Hoʻopili ka ʻike o ka ʻatikala i kā mākou kumumanaʻo o ka hoʻoponopono hoʻoponopono. E hōʻike i kahi kaomi hemahema ʻaneʻi.

4 manaʻo, waiho i kāu

E waiho i kāu manaʻo

Kāu leka uila aae? E,ʻaʻole e paʻiʻia.

*

*

  1. Ke kuleana o ka ʻikepili: AB Internet Networks 2008 SL
  2. Ke kumu o ka ʻikepili: kaohi SPAM, hoʻokele ʻōlelo.
  3. Legitimation: Kou ʻae
  4. Ka kamaʻilio ʻana o ka ʻikepili: ʻaʻole e hōʻike ʻia ka ʻikepili i nā ʻaoʻao ʻekolu koe ka mana o ke kānāwai.
  5. Pūnaewele mālama: Pūnaewele i mālama ʻia e Occentus Networks (EU)
  6. Nā Kuleana: I kēlā me kēia manawa hiki iā ʻoe ke palena, hoʻōla a kāpae i kāu ʻike.

  1.   Pedro ia

    Aʻo maikaʻi loa, akāka loa a maʻalahi hoʻi.

  2.   ʻōpala ia

    ʻĀ, pono wau e melon nui 🙁 no ka mea ʻaʻole holo pono ia naʻu. Ua hopu wau i ka waiwai i kahi String a lawe ia i ka huaʻōlelo akā ʻaʻole ia e hāʻawi i ka lepili, ma ka liʻiliʻi ʻaʻole ia e pena ia mea, no ka mea e hoʻāʻo wau e ʻike i ka lepili. ..

  3.   leo2279 ia

    Maikaʻi loa i kāu mau kumu aʻo, wehewehe maoli ia i kēia ulu ʻana no ka iphone, lana koʻu manaʻo e hoʻomau ʻoe i ka paʻi hou ʻana i nā ʻōlelo aʻo.

    Aloha

  4.   Mariano ia

    Aloha, maikaʻi a pau, akā ʻaʻole holo pono ia. I mea e hana ai, pono wau e hoʻopili i ka ʻike o ka mea kūkulu hale me ka ʻike i ka pahu, ke aʻo ʻoe e hana me ka textfield a me ka lepili. No ke koena, mahalo nui loa.