현재 배열의 비디오를 재생하는 앱을 만들고 있습니다. 사용자가 "다음"버튼을 누를 때 배열의 비디오가 무작위로 선택되도록 랜덤 라이저에 배열을 연결했습니다. 다음 버튼은 잘 작동하지만, 내가 고민하고있는 것은 뒤로 버튼이다. 사용자가 '뒤로'버튼을 눌러 이전 동영상으로 돌아갈 수 있기를 바랍니다. 나는 이것을하기 위해 몇 가지 방법을 연구했지만 아무도 연구하지 못했습니다. 누군가 내 코드를 아래에서 살펴보고 나에게 몇 가지 제안을 할 수 있다면 크게 감사하겠습니다! 공간을 절약하기 위해 배열에서 인덱스 하나만 선택했습니다. 또한 역 열거에 대한 여러 게시물이 있다는 것을 알고 있습니다. 아무도 성공하지 못했습니다. 연구가 끝나면 이것이 나의 마지막 수단입니다.무작위 NSArray를 통한 역 열거하기 Objective C
@implementation MajesticViewController
@synthesize arrayName = _arrayName;
- (void)viewDidLoad
{
[super viewDidLoad];
//Heres the array containing the videos
_arrayName = [NSArray arrayWithObjects:
// video 0- losing you
@"<iframe width=\"279\" height=\"199\" src=\"http://www.youtube.com/embed/YjvRydejkYY\" frameborder=\"0\" allowfullscreen></iframe>", @"<iframe width=\"279\" height=\"199\" src=\"http://www.youtube.com/embed/nosOsDG38nQ?rel=0\" frameborder=\"0\" allowfullscreen></iframe>", nil];
[self pickSong:_arrayName];
}
//This is the next button
-(IBAction)newSongButton:(id)sender
{
[self pickSong:_arrayName];
}
//This randomly picks the next video
-(void)pickSong:(NSArray *)arrayName
{
int r = arc4random() % 47;
//int r = 46; /////tester
if (r==0)
{
NSString *randomResponse = [arrayName objectAtIndex:0];
[[self myWebView] loadHTMLString:randomResponse baseURL:nil];
}
배열을 임의로 섞어서 반복 할 수 없습니까? –