ios - keeping track of newly created subviews -


every time create subview want update int can reference specific subview later.

for example,

class circularkey: uiview {     var oscid = 0; //init 0      init(origin: cgpoint) {         oscid = oscid + 1;         ...      }  } 

can have number update every time create new circularkey each circularkey has own unique self.oscid?

thanks

edit:

i'm trying viewcontroller.swift responsible adding these subviews.

  class viewcontroller: uiviewcontroller {      var numoscs = 0; //update when add new bosc     ....       ...     func didtap(tapgr: uitapgesturerecognizer) {            numoscs = numoscs + 1           let newcircularkey = circularkeyview(origin: tappoint, oscindex: numoscs)             self.view.addsubview(newcircularkey)      } 

my assumption upon every didtap numoscs shall incremented, stays @ zero. do?

edit2: never mind, works :d

i believe best solution have invoking controller keep track of how many has made far. all

i think controller adding subviews should handle allocating new id every time (similarly tagging buttons)

regardless, if did want create unique identifier each subview maybe try creating 1 cacurrentmediatime() unique identifier

e.g.

class circularkey: uiview { var keyid = 0.0; //init 0  init(origin: cgpoint) {     keyid = cacurrentmediatime()     ...  } 

}

cacurrentmediatime() returns amount of time app has been active double precision, adding sub views in loop should return unique identifiers each time.

i didn't want convert number int value , screw conversion in main answer think do:

keyid = int(cacurrentmediatime()*1000000000)  //converting number of nanoseconds since start of app 

double check though!

as side note: don't use nsdate syncs server , 'hiccup' in value, hard debug later down line.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -