iPhone - detailView controller
I am having a tableView which lists the contents开发者_C百科 directory which includes jpg, pdf, zip, mp3, mp4, sql,.. files and even folders. In the next step, I am having a detailView which displays some properties of the selected file such as fileName, fileSize, filePath, fileType. Everything works perfect.
But actually my plan is to include a additional option in the detailView.
That is,
- If the selected file in the tableView is a image file, it should open a imageView in the detailView to display that image.
- If the selected file is a mp3, it should open a player to play the song in the detailView.
- If the selected file is a video or mp4 file, it should open a player to play that video in detailView.
- If the selected item is a folder, it should again open a tableView which dispalys the contents of the folder.
- For other files, it should push a alertView regarding that it is a unknown file.
Hope my concept was narrated well. I got the methods for playing the .mp3 and .mp4 files. Now I am stuck in pushing the imageView and in case of a folder. I have no ideas to proceed both the methods.
This is my tableView
This is my detailView for video file
This is my detailView for a .mp3 file
This is the detailView left empty for my imageView.
Please help me to proceed with some sample codes. Thank you in advance.
Judging by your screenshots and progress of implementing the other filetypes, I assume you are able to pass the information of the file path to the detail view. So, for the image file, I am going to discuss how to display it into a UIImageView
.
For the image view, You will want create a UIImage
with the path.
Code example below: Assume that pathString
is an NSString*
with the image path, and that imageView
is now a UIImageView
which should display the image. This code would reside in the -viewDidLoad
method of the detailViewController
handling the image display.
UIImage* theImage = [[UIImage alloc] initWithContentOfFile:pathString];
imageView.image = theImage;
[theImage release];
As for the folder view, this is a bit different. For the best result you will want to recursively load the tableViewController
you are using to display the list of files now (so that it will inherit all the file/folder handling recursively).
I would suggest to add an instance variable like folderPath
to the tableViewController
that you set before actually pushing the view. And the tableViewController
should use this as the base path.
Code example below: Assume that pathString
is an NSString*
with the destination path, and that detailViewController
is now an instance of the new tableViewController
to be opened. This code would reside in the method that will create the new detailViewController
to be displayed, somewhere within tableView:didSelectRowAtIndexPath:
detailViewController.folderPath = pathString;
[self.navigationController pushViewController:detailViewController animated:YES];
You should then implement in the -viewDidLoad
method of the tableViewController
, on what folder content should be read from the folderPath
instance variable.
This method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
is called when there is touch occurred on some cell.
You can get cell with [yourTableView cellForRowAtIndexPath:cellIndex];
After that you can see type property, and open appropriate viewcontroller.
[self.navigationController pushViewController:detailViewController animated:YES];
When you create your detailView, you should overload the init with additional parameters that indicate the type of media to display and the url/file of this resource.
If it's for an image, look at this post
精彩评论