I am having a tableView which lists the contents 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
Related
I am developing one application.In that first page having one UIWebView.And i create a property for that one.And i created a object for that class in another class and give the html data for that webview like as below.But it didn't show the data on UIWebView.Please tell me how to do that one.
ViewController *view=[[ViewController alloc]init];
NSString *result1 = [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];
NSString *htmldata=[NSString stringWithFormat:#"<html>%#</html>",result1];
[view.web loadHTMLString:htmldata baseURL:nil];
This result1 string contain html data without html tag.That' why iam adding that tags.
Hope you had called pushViewController or popViewController to present the view or added the view object's view as a subview of the current view. Then make sure that the webview is allocated, given a frame and added as a subview of ViewController. You did not used the method initWithNibName:, therefor, if the webview is created from xib, it will not take.
I was wondering how I can add an int to a bundle and pass it to the next view that I am calling.
What I am trying to do is click an item on a UITableView and that will call the next .m file and pass the int that pertains to a document that I will be looking up online. This document has a specific id and without passing it to the next view I will not be able to get the list that I need to compile and show on the next UITableView.
How are you displaying the next view? Can you not just add an instance variable to the view to be called?
View2 *view = [[View2 alloc] init]];
[view setSpecificId:myId];
display the view....
I'm developing a navigation app and also following the chapter 9 in "Beginning iPhone 4 Development". I want my application to be like this:
a rootViewController contains an array of controllers in viewDidLoad part (like the book introduced);
after users click on any row of the controllers array, the app will turn to the corresponding screen which also contains an array of controllers;
then each row in the array will lead to an image after a click;
That's it. I have completed the coding for rootViewController and other controllers in the viewDidLoad controller array in rootViewController.m, but it just won't go the next controller array.
If anyone knows how to solve this problem, please kindly help me. Thank You ~~
It seems you forget to implement tableView Delegate methods. You need to implement didSelectRowAtIndexPath method; when you tap on a cell this method will be called. Then in the method you need to get UIImage Object which you have prefilled in an array through this line of code
UIImage* selectedImage = [arrayOfImages objectAtIndex:indexPath.row];
Then allocate your imageViewController and pass the image object to the imageViewController and then push the controller on stack. Hope you understand if not post the code.
This is really frustrating as I've tinkered with previous versions of Xcode and have done this before but playing around with a new app now, it's not working for some reason.
I have the app open to a UITableView and want it to load to a detail UIView once I select a cell. However, when I choose a cell in the iPhone simulator, it just highlights the cell blue and doesn't load the view.
Here is the code I'm using the the RootViewController:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WorkoutViewController *workoutViewController;
workoutViewController = [[WorkoutViewController alloc] initWithNibName:#"WorkoutViewController" bundle:nil];
workoutViewController.workoutName = [workouts objectAtIndex:indexPath.row];
[self.navigationController pushViewController:workoutViewController animated:YES];
[workoutViewController release];
workoutViewController = nil;
I have the view linked to the File Owner in the WorkoutViewController.xib file. When I put in a breakpoint at #implementation WorkoutViewController, it does get to that breakpoint but it goes to the #synthesize line and then jumps right back out to [self.navigationController ...etc]; and never returns back to the WorkoutViewController.m file.
I would guess that you didn't set the ViewController to be the TableView's delegate. To check, open your ViewController xib-file and rightclick FilesOwner. Under Referencing Outlet you would usually have both delegate and data source" connected to your TableView. If that is not the case, drag New Referencing Outlet to your TableView.
If I'm wrong and they are all connected, you might want put a breakpoint at the beginning of your didSelectRowAtIndexPath method. Does the debugger stop there, once you select a row?
It might also be worth mentioning that a breakpoint at #implementation usually doesn't make much sense, you would rather want to place it in a method like init. Also, even though you are using Xcode 4 now, this is unlikely to be the cause of your problem, it looks more like an implementation issue.
Hope this helps, if you need further help just let me know!
Doh! Problem resolved. I had forgotten to actually put the RootViewController into a navigation controller on the MainWindow.xib. Appreciate the responses.
when you click "Share" in my app you'll show an ActionSheet like this:
Take photo
Select photo from Library
Cancel
You tap "Take photo" and you'll see an ImagePicker, with "presentModalViewController".
You take a photo and you select "OK" in the ImagePicker.
Here, I want the photo just taken in a new view with other label. Like this:
(new view)
Little photo (just taken)
- Label 1 (ex. Title of photo)
- Label 2 (ex. Location of photo)
and a button "Share" for sharing your photo and its infos.
How can I do this? I'm stopped after take the photo. How can I send my photo (in a imageview) to another view?
Thanks
for this,
make some global varible in appDelegate class and make them property.
for saving Image make UIImage object in app delegate and for title and path make string variables and make all these : property then.
then when you select image from modelView at the selection time you must set app delegate properties(image,title,path).and navigate to other page and on viewWillAppear of new page
set your controls (ImageView and labels) by these objects.
I hope, it helps you. You need to code this logic.
Some one already suggested for that by using appDelegate.
you can do in other way too.
just declare some variable like imagePath and imageTitle in the 2nd view controller. and set property to them like
#property (nonatomic,retain) NSString *imagePath;
And then in the 1st view controller access those variables like
secondViewControllerObj.imagePath = #"Give Image Path Here";
then you can access the imagePath in the 2nd View Controller as self.imagePath
Regards,
Satya