Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用字符串设置字符串数组,这些字符串将通过iphone文本上的数组显示?_C++_Iphone_Objective C_Arrays - Fatal编程技术网

C++ 如何使用字符串设置字符串数组,这些字符串将通过iphone文本上的数组显示?

C++ 如何使用字符串设置字符串数组,这些字符串将通过iphone文本上的数组显示?,c++,iphone,objective-c,arrays,C++,Iphone,Objective C,Arrays,我对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;

我对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;

    }

}
}


我希望能够在Iphone视图中显示这些字符串。并且可以单击下一个或上一个按钮转到下一个或上一个字符串,该字符串可以是从蓝色到红色或从红色到蓝色。基本上,如果有任何教程可以帮助我,或者如果你知道如何帮助我,我将不胜感激。谢谢

为什么不使用一个
int
变量和数组中字符串的当前位置,以及两种方法
goPrev
-
goNext
来递增和递减
int
变量

在界面中:

UIButton *btn;
int step;
NSArray *titles;
在实施过程中:

-(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];
}
-(无效)设置{
标题=[NSArray数组,其对象为:@“标题1”、“标题2”、“标题3”、“标题4”,无];
btn=[UIButton按钮类型:UIButtonTypeCustom];
}
-(无效)goPrev{
如果(步骤>0){
步骤--;
}
[btn setTitle:[titles objectAtIndex:step]用于状态:UIControlStateNormal];
}
-(无效)goNext{

如果(stepHow)你会把所有的东西都放在课堂上吗?@JacobBrans我刚刚给你展示了
previous
next
方法。
-(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];
}