我是 iphone 开发的新手,但我以前做过 android。以下是我在 java 中所做的事情,我想将其转换为 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 the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(starting.rt.R.layout.relationship);
AdView ad = (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) {
// return 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;
}
}
}
您将如何将代码中的内容从 android 转换为 iphone。
到目前为止,我有这个适用于 iphone 的代码,我只是不知道从那里去哪里。
(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];
}
我希望能够在 Iphone 视图中显示这些字符串。并且能够单击下一个或上一个按钮转到下一个或上一个字符串,可以是从蓝色到红色或红色到蓝色。基本上,如果有任何教程可以帮助我,或者如果您知道如何提供帮助,我将不胜感激。谢谢!