Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andynov123

macrumors newbie
Original poster
Jan 12, 2011
6
0
I'm not sure if the table view is what I would use but I'm having trouble figuring out how to store 10-20 audio files in a scrollable list like the iPod app and play a song when it is selected. Any help is appreciated.
 
MVC Patterns, have a data controller which has your data (or if you're lazy, in the viewController), have a tableview which gets the data via the index of the array from the data controller. On a didSelectRowAtIndex, play that sound that it gets also from the index from the same array..
What is your question exactly? because "i'm trying", isn't that helpful >.<
 
MVC Patterns, have a data controller which has your data (or if you're lazy, in the viewController), have a tableview which gets the data via the index of the array from the data controller. On a didSelectRowAtIndex, play that sound that it gets also from the index from the same array..
What is your question exactly? because "i'm trying", isn't that helpful >.<

My question is instead of listing numbers 0-9 I want it to store audio files. When a file is pressed I want that file to play. How do I do this with following code.(Audio Files are in my resources folder)

.h
Code:
#import <UIKit/UIKit.h>

@interface TableViewViewController : UIViewController  <UITableViewDataSource, UITableViewDelegate> {

}

@end

.m

Code:
#import "TableViewViewController.h"

@implementation TableViewViewController


- (NSInteger)tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section {
	return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	// Identifier for retrieving reusable cells.
	static NSString *cellIdentifier = @"MyCellIdentifier";
	
	// Attempt to request the reusable cell.
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
	
	// No cell available - create one.
	if(cell == nil) {
		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
									  reuseIdentifier:cellIdentifier];
	}
	
	// Set the text of the cell to the row index.
	cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
	
	return cell;
}
- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	// Show an alert with the index selected.
	UIAlertView *alert = [[UIAlertView alloc] 
						  initWithTitle:@"Item Selected"                         
						  message:[NSString stringWithFormat:@"Item %d", indexPath.row]                     
						  delegate:self       
						  cancelButtonTitle:@"OK"           
						  otherButtonTitles:nil];
	[alert show];
	[alert release];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end


THis is what the ios simulator looks like right now.
http://imageshack.us/photo/my-images/593/screenshot20120725at124.png/
 
Last edited:
This is the first app I've ever created so keep that in mind.

I'm not sure how to implement didselectRowatIndex. Can you show me?
 
How did you implement the other parts of the tableview? ;)
it's also a delegate method.. (if you hold command, and click on the UITableviewDelegate, or go to Apple documentation and look for the UITableviewdelegate, the method name is right there. this method will be called each time a row is clicked. And you can play a sound in there :)
 
I'm not sure if the table view is what I would use but I'm having trouble figuring out how to store 10-20 audio files in a scrollable list like the iPod app and play a song when it is selected. Any help is appreciated.

You posted this same question on the "iPhone Dev SDK" forum, and I answered you there.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.