c++ - How to set up a string array with strings that would display through the array on a text for iphone? -
i'm new iphone development have done android before. next have done in java , want convert on iphone.
public class relationshiptipsactivity extends activity implements onclicklistener { private static final int swipe_min_distance = 120; private static final int swipe_max_off_path = 250; private static final int swipe_threshold_velocity = 200; private gesturedetector gesturedetector; view.ontouchlistener gesturelistener; string facts[] = {"coming soon", "coming soon", }; textview display, display1; textview counter; button begin; button next; button previous; button random; random myrandom; int index = facts.length; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(starting.rt.r.layout.relationship); adview advertisement = (adview) findviewbyid(r.id.ad); ad.loadad(new adrequest()); display1 = (textview) findviewbyid(starting.rt.r.id.begin); display = (textview) findviewbyid(starting.rt.r.id.tvresults); counter = (textview) findviewbyid(starting.rt.r.id.tvcounter); next = (button) findviewbyid(starting.rt.r.id.next); previous = (button) findviewbyid(starting.rt.r.id.previous); random = (button) findviewbyid(starting.rt.r.id.random); next.setonclicklistener(this); previous.setonclicklistener(this); random.setonclicklistener(this); // display.setontouchlistener(this.gesturelistener); myrandom = new random(); // gesturedetector = new gesturedetector(new mygesturedetector()); // gesturelistener = new view.ontouchlistener() { // public boolean ontouch(view v, motionevent event) { // homecoming gesturedetector.ontouchevent(event); // } // }; } private void showdisplay() { display.settext(facts[index]); counter.settext(string.valueof(index + 1) + "/" + string.valueof(facts.length)); } public void onclick(view arg0) { // todo auto-generated method stub switch (arg0.getid()) { case starting.rt.r.id.next: index++; if (index > facts.length - 1) { index = 0; } showdisplay(); break; case starting.rt.r.id.previous: index--; if (index < 0) { index = facts.length - 1; } showdisplay(); break; case starting.rt.r.id.random: index = (myrandom.nextint(facts.length) - 1); if (index < 0) { index = facts.length - 1; } showdisplay(); break; } }
}
how convert along lines of code android iphone.
i have code far iphone, don't know go there.
(ibaction) clicked:(id)sender{ nsarray *titleofbutton = [sender titleforstate:uicontrolstatenormal]; //nsstring *newlabeltext = [[nsstring alloc]initwithformat:@"%@", titleofbutton]; nsarray *initializednsarray = [nsarray arraywithobjects: @"red", @"blue", @"green", @"yellow", nil]; labelstext.text = initializednsarray; [initializednsarray release];
}
i want able display strings within iphone view. , able click next or previous button go next or previous string bluish reddish or reddish blue. if there tutorials out there help me or if know how help appreciate. thanks!
why not have int
variable current position of string array , 2 methods goprev
- gonext
increments , decrements int
variable.
in interface:
uibutton *btn; int step; nsarray *titles;
and in implementation:
-(void)setup { titles = [nsarray arraywithobjects:@"title 1",@"title 2",@"title 3",@"title 4", nil]; btn = [uibutton buttonwithtype:uibuttontypecustom]; } -(void)goprev { if (step>0) { step--; } [btn settitle:[titles objectatindex:step] forstate:uicontrolstatenormal]; } -(void)gonext { if (step<titles.count-1) { step++; } [btn settitle:[titles objectatindex:step] forstate:uicontrolstatenormal]; }
c++ iphone objective-c arrays
No comments:
Post a Comment