[Solved] objective-c index in an Array [closed]


Remove these lines:

    [acat addObject:@"cat1"];
    [acat addObject:@"cat2"];
    [acat addObject:@"cat3"];
    [acat addObject:@"cat4"];

Declare your array and NSURL not in viewDidLoad, Do this instead in your .h:

@interface AZViewController : UIViewController

{

    NSInteger _acatindex;
     NSMutableArray *acat;
    NSURL *url;
}

@property (weak, nonatomic) NSMutableArray *acat;

- (IBAction)catbutt:(id)sender;

Now cut the following code from viewDidLoad():

url = [[NSBundle mainBundle] URLForResource:[acat objectAtIndex:_acatindex] withExtension:@"wav"];
    NSAssert(url, @"URL is valid.");
    NSError* error = nil;

self.catplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if(!self.catplayer)
    {
        NSLog(@"Error creating player: %@", error);
    }

and paste it in - (IBAction)catbutt:(id)sender above _acatindex++;

Hope this will help.

1

solved objective-c index in an Array [closed]