2012-11-22 24 views
0

我是新來的手機編程。圖像和音頻我有存儲在私人文檔文件夾中,在數據庫中我創建了ID,名稱,圖像路徑,音頻路徑我已經存儲了所有那些想在數據庫中。當iam從數據庫中檢索數據時,它在控制檯中的顯示就像這樣。如何在iPhone上使用圖像路徑和音頻路徑播放歌曲圖像

1/Picture0001 |/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0001.jpg | Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song.mp3

2 | Picture0002 |/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0002.jpg |/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9 -A4DBF1736062 /文件/ Tauky /音頻/ song1.mp3

現在我得到了像路徑這在控制檯使用這個我想只顯示圖像在表視圖中,如果單擊該圖像意味着它必須在下一個視圖中播放歌曲。現在我要做什麼我能夠顯示錶視圖中的路徑而不是路徑,我想顯示圖像,如果點擊該圖像,我想播放歌曲。這個想法如何做任何想法。是否可以播放歌曲使用路徑圖像路徑和音頻路徑。

回答

1

聲明兩個的NSMutableArray性質(使用一個類而不是兩個的NSMutableArray)

@property (strong,nonatomic) NSMutableArray *imageCollection; 
@property (strong,nonatomic) NSMutableArray *songCollection; 

分配它們viewDidLoad

self.imageCollection = [[NSMutableArray alloc] init]; 
self.songCollection = [[NSMutableArray alloc] init]; 

添加對象

[self.imageCollection addObject:@"Picture0001"]; 
    [self.imageCollection addObject:@"Picture0002"]; 

    [self.songCollection addObject:@"/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0001.jpg|/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song.mp3"]; 
    [self.songCollection addObject:@"/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0002.jpg|/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song1.mp3"]; 

Implement UITableView

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; 

    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];   
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease]; 


    } 
    cell.textLabel.font = [UIFont systemFontOfSize:12]; 
    NSString *imageName = [self.imageCollection objectAtIndex:indexPath.row]; 
    cell.imageView.image = [UIImage imageNamed:imageName]; 
    cell.textLabel.text = [arry objectAtIndex:indexPath.row]; 

    return cell; 
} 

實施的UITableView * didSelectRowAtIndexPath方法代表 *

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *songURL = [self.songCollection objectAtIndex:indexPath.row]; 

    //play song here or pass the songURL to another controller and play it in view didload 

} 
+0

喜在tableview中圖像顯示不只是文本顯示,如果單擊單元格的黑色,歌曲不是正在播放。[arry objectAtIndex:indexPath.row];我必須給出imagecollection – user1796298

+0

調試和檢查...... –