두 개의보기 컨트롤러가있는 xcode 응용 프로그램이 있습니다. 두 개의 단추가 있습니다 (첫 번째 단추는 alertview를 표시하는 단추이고 두 번째 단추는 두 개의 단추 사이에 이동하는 단추입니다. 보기). 두 번째보기에서 나는 4 개의 세그먼트가있는 세그먼트 컨트롤러가 있고 그 중 하나를 선택하면 첫 번째보기로 돌아가서 세그먼트 컨트롤러보기로 돌아갑니다. 세그먼트 컨트롤러는 첫 번째 세그먼트로 돌아갑니다 ... 어떻게 수정합니까? 이 ? 나는 당신의 질문을 이해한다면 여기 Xcode - 분할 컨트롤이 기본값으로 변경
가하는 .m 파일//
// ViewController.m
// iBored
//
// Created by Yannai on 12/15/12.
// Copyright (c) 2012 Yannai Harel. All rights reserved.
//
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
boredInt = arc4random()%30+1;
boredString = [[NSString alloc]init];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)weatherButton:(id)sender {
}
-(void)iBoredAction {
switch (boredInt) {
case 1:
boredString = @"Draw!";
break;
case 2:
boredString = @"Try to earn money!";
break;
case 3:
boredString = @"Climb on trees!";
break;
case 4:
boredString = @"Do homework!";
break;
case 5:
boredString = @"Watch TV!";
break;
case 6:
boredString = @"Go on a run!";
break;
case 7:
boredString = @"Connect to your innerself - meditate!";
break;
case 8:
boredString = @"Play on the computer!";
break;
case 9:
boredString = @"Call a friend!";
break;
case 10:
boredString = @"Go to a friend!";
break;
case 11:
boredString = @"Play with your pet!";
break;
case 12:
boredString = @"Take your pet on a walk!";
break;
case 13:
boredString = @"Play on an instrument - if you don't know try to learn!";
break;
case 14:
boredString = @"Watch youtube videos!";
break;
case 15:
boredString = @"Listen to music!";
break;
case 16:
boredString = @"Read a book!";
break;
case 17:
boredString = @"Go to iFunny!";
break;
case 18:
boredString = @"Watch a movie!";
break;
case 19:
boredString = @"Do some experiments!";
break;
case 20:
boredString = @"Play soccer!";
break;
case 21:
boredString = @"Play basketball!";
break;
case 22:
boredString = @"Go for a ride on your bike!";
break;
case 23:
boredString = @"Do some exercises!";
break;
case 24:
boredString = @"Build a treehouse!";
break;
case 25:
boredString = @"Build a fort!";
break;
case 26:
boredString = @"Record short and cool films!";
break;
case 27:
boredString = @"Start programming!";
break;
case 28:
boredString = @"Go online!";
break;
case 29:
boredString = @"Do some research about a subject you like!";
break;
case 30:
boredString = @"Go outside and stare at the sky!";
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"iBored" message:boredString delegate:self cancelButtonTitle:@"Nice Idea" otherButtonTitles:@"Pass",nil];
[alert show];
}
-(IBAction)switchWeatherSwitch:(id)sender {
if (weatherSwitch.on) {
weatherOut.enabled = YES;
NSLog(@"on");
}
else {
weatherOut.enabled = NO;
NSLog(@"off");
}
}
- (IBAction)iBored:(id)sender {
if (weatherOut.selectedSegmentIndex == 0) {
NSLog(@"Sunny");
}
else if (weatherOut.selectedSegmentIndex == 1) {
NSLog(@"Rainy");
}
else if (weatherOut.selectedSegmentIndex == 2) {
NSLog(@"Windy");
[self iBoredAction];
}
else if (weatherOut.selectedSegmentIndex == 3) {
NSLog(@"Snowy");
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
[self iBoredAction];
}
}
@end
이해할 수 없습니다. 세그먼트 컨트롤의 일부 코드를 게시하십시오. 더 많은 요구 사항을 설명하십시오. –
세그먼트를 누르면 첫 번째보기로 돌아가고 두 번째보기로 바로 돌아가고 자합니다. 그러나 세그먼트는 마지막 클릭 위치를 유지해야합니다. 권리? –
아니요 세그먼트를 일종의 설정으로 설정하고 싶지만 처음보기로 돌아 가면 기본으로 돌아갑니다 ... 일부 코드를 추가했습니다 – user1289671