Using table view to store audio files

Discussion in 'iOS Programming' started by andynov123, Jul 24, 2012.

  1. andynov123 macrumors newbie

    Joined:
    Jan 12, 2011
    #1
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Views don't store anything. They act as views only. Your model stores the data.
     
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    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 >.<
     
  4. andynov123, Jul 25, 2012
    Last edited: Jul 25, 2012

    andynov123 thread starter macrumors newbie

    Joined:
    Jan 12, 2011
    #4
    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/
     
  5. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    Like I mentioned above, where is the didselectRowatIndex?
    You don't have an array with sounds.. so where would the app get it from? ;)
     
  6. andynov123 thread starter macrumors newbie

    Joined:
    Jan 12, 2011
    #6
    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?
     
  7. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #7
    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 :)
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    Have you done any tutorials? What were they?

    Have you studied any books, in which you did the exercises? What were they?
     
  9. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #9
    You posted this same question on the "iPhone Dev SDK" forum, and I answered you there.
     
  10. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #10
    Duncan, that forum back up? Still as much spam as when I was active there? (under other name).
     
  11. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #11
    You posted the question today. Why ask if it's back up if you posted a new question today?
     
  12. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #12
    Me? I haven't been on iPhoneDevSDK in a long time..
    Aren't you talking about the OP posting the question instead of me?
     
  13. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #13
    Oops, sorry. I thought your post was the OP. That'll teach me to read more carefully.
     
  14. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #14
    That's alright.. But since OP have been answered by you on iPhoneDevSDK, he can set it as resolved, right?!
     

Share This Page