I have a simple UITableView setup, but I want each item to contain an image. So when you click on an item is goes to a image. How do you think I would do this? I have about 10 items in my list(array) that will in the TableView.
The UITableViewDataSource Protocol is a must read. Once the protocol has properly been implemented, using the tableView:didSelectRowAtIndexPath is your answer. Depending on your implementation requirements, this answer could vary slightly but the protocol remains the solution.
You will need a UITableViewCell subclass.
http://zcentric.com/2008/08/05/custom-uitableviewcell/
This gives you almost what you need.
If you haven't already done so, add a navigation controller to handle switching between the tableview and the image.
Then overwrite the tableview method :didSelectRowAtIndexPath
[self.navigationController pushViewController:theViewControllerContainingTheImage animated:YES];
Arrange the items in the tableview and in the Array
After that use this in the didselectrowAtIndexPath delegate of UITableView
[myImageView setimage:[picArray objectAtIndex:indexpath.row]];
Related
I have a project utilizing storyboards that uses UITableView in tandem with a Navigation Controller. Its layout is similar to apple's iOS Address Book where there is a table of objects, and clicking on a cell pushes a view onto the navcontroller with that objects's details (properties). I am having trouble using the prepareForSegue method in harmony with the table view's didSelectRowAtIndex. I need a way for the prepareForSegue to know about the row passed in didSelectRowAtIndex so i can pass it's properties to the detail view controller being pushed since prepareForSegue gets called before didSelectRowAtIndex does. If possible I would still like to use the storyboard segue but if there isn't a way i can progamatically push/pop. There is another question similar to this on stackoverflow but it never really was answered, it kind of just rambled on.
If you know a work-around please let me know, thank you!
You can not use didSelectRowAtIndexPath: at all. You can get the index path in prepareForSegue: like this:
UITableViewCell *cell = (UITableViewCell*) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
If I want to list some items from a database, do I need to add a UIView and a UITableView to my ViewController? or just add the UITableView to my ViewController?
You must already be having a UIView as part of your ViewController, Just add UITableView as a subview to your UIView.
The UIView of a ViewController can be accessed as [self.view];. So what you need to do is [self.view addSubview:yourTableView];. Using setFrame properly sets it in the x,y,width,height that you need.
Just add the UITableView cause you are already have a UIView, Please check this tutorial on how to use UITableView.
its just depend on your project layout if you want to add tableview then you can use predefined function like didselectrow,moverow,editingrow,willdisplay etc...it totally depend on your need and layout specification and last thing tableview is better than using view instead on another view.
Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:
I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?
Possible solutions I've founded today
1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)
2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?
I would ditch the UIScrollView and just use a UITableView. You can add a UIView object as the tableHeaderView of the UITableView just by dragging it in in Interface Builder. Now since everything is part of the UITableView hierarchy, everything will scroll together as expected.
You could also try setting delaysContentTouches to NO on your scrollView. Depending on your setup, this may make the scroll view respond to the touch first instead of the table view.
From Apples UIScrollView Docs:
delaysContentTouches
A Boolean value that determines whether the scroll view delays the
handling of touch-down gestures.
#property(nonatomic) BOOL delaysContentTouches
Discussion
If the value of this property is YES, the scroll view delays handling
the touch-down gesture until it can determine if scrolling is the
intent. If the value is NO , the scroll view immediately calls
touchesShouldBegin:withEvent:inContentView:. The default
value is YES.
You'll have to (as you've mentioned) add the UIView containing the image and buttons to the actual UITableView. Embedding it in the scroll view will produce the undesired behavior that you're seeing.
I would recommend returning the UIView as the header view for the first section of your table view. You can do this by implementing the UITableViewDelegate method:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
If you maintain an IBOutlet to the view containing your image/labels, you can return it here.
this is same demo i hope its helps you from iphone sorce code library
http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html
thank you
I want the effect of a UISplitViewController however I am not using the split view template.
Is it relatively easy to achieve without the template? And with using normal UIViewController?
What I want it a customary sized and positioned UITableView which then has a customary sized detail view which then of course goes into a popover and detail view when portrait.
Doing it without Interface Builder, you would create a UIViewController class. In the viewDidLoad method of that class, create a UIView or a UITableView with the frame origin where you want it and a size that you want. (Release it in the viewDidUnload method.) Then set the UIViewController's self.view to point to this new view.
self.view = [[UIView alloc] initWithFrame:...]; // edit - added in response to your question
If you created a UIView, then you will want to put your UITableView inside this new view. (This approach lets you add more items to the container UIView if you need to.)
Make sure your UIViewController adheres to the UITableViewDelegate and UITableViewDataSource protocols. Add the delegate and datasource methods and you should be good to go.
This new view can cover other views, or you can size the other views to fit beside it. You only need to set there frames according to what you want to do with them.
There are some limitations if you use a UITableViewController, so a lot of people recommend using a UIViewController instead. like I described above. You can google for more info on that topic.
Just great a new temporary Xcode-project from that template and judge yourself, if it is complicated for you, to adept your (real) code.
Yes. You can do it quite easily. Just use delegates to pass messages between the left and the right side views (root and detail). For instance the didSelectRowAtIndexPath tableView method could be used along with delegation to pass a message to the right sided detail view. Tap a cell on the left table, show its text as a Label on the right side. Its just a simple example. And yes you can handle the rotations and send left side view into a UIPopoverController as well, thus giving the detail view full screen real estate in Portrait orientation.
Also try MGSplitViewController . It gives you a lot of other customization options on a split view controller.
please patient with my poor english.
I'd bad concept of UIView, UIViewController, UITableView, UITableViewController..
Now I'd created a NavigationController and ViewController with SegmentedControl and I don't know how to add a custom TableView in the ViewController. All the examples I've seen are subclassing a UITableViewController as it is a whole table without other control in between.
Can anyone show me some guideline to get to create a Form's like apps?
Thank you very much.
I am answering my own answer.
UITableView has two properties call headerView and footerView
these two view are able to put in any custom view to display your custom component on the top and foot of the table.