How can I inherit a UIScrollView like what the UITableView do? - iphone

I want to create a scroll view filled with grid cell of irregular size.
The UITableView, inheriting the UIScrollView, alloc cells effectively.
I just want to do the same.
Of couse, it is possible to use UIScrollViewDelegate to detect scroll event. But that will hold the delegate property. I want to use the delegate property as it used to be. So I have to inherit the UIScrollView as the UITableView does.
The question is how to do that?
Which method should I override to get the scroll event?

If you only want to implement cells with arbitrary heights, then you could simply implement tableView:heightForRowAtIndexPath: and you can decide the height for each cell in your table.

You should watch the WWDC 2010 video for UIScrollView, which includes lots of information about how to lay out many views. https://developer.apple.com/videos/wwdc/2010/
You could also look at the PhotoScroller example code for how to tile many views.

Related

UIScrollView with a UITableView mechanism

I am looking for a third party library that would allow me to use a UIScrollView with a UITableView mechanism, so it will have something like viewForRowAtIndexPath, numberOfRowsAtIndexPath.. reusing views. I know a UITableView is a subclass of UIScrollView, but I want to do more customization that will be kind of hard when using UITableView.
Since UITableViewCell is a subclass of UIView, you could use a custom UITableViewCell, adding your view as the UITableViewCell's subview. I am assuming that all your views are of the same size. (In the table view controller's init method, remember to set self.tableView.rowHeight to a value that will accommodate the heights of your views.)
See the Customizing Cells section of Apple's Table View Programming Guide for iOS for more info.

UIScroll view + UIView + UITableview question

A UITableview inherits from a UIScrollview. But, if u want a UITableview within a scrollview the best way to do this is embed it in a UIView and add that as a subview to a scrollview.
Is the above correct?
If yes, then UIScrollView inherits from UIView.So finally, when all three are put in the same space how do you know which is calling a particular method.
This is a suddenly-confused-newbie question. So , thanks for your patience! :P
Both UITableView and UIScrollView inherit from UIView. That's not the point. UITableView and UIScrollView as well as UIView are all components. Think of them as building bricks. By them selves they are nothing more but peaces from which you build your application. If you want them to work together and perform tasks you should design and implement controllers (UIViewControllers or UITableViewControllers) that would know how to manage each and every "bricks".
In terms of using and UITableView in the UIScrollView.
Case 1. UITableView needs to be scrollable.
If that's the case then you will have a problem, b/c both UIScrollView and UITableView respond to swipe events, and you will get a collision, and unexpected behavior when scrolling.
Case 2. UITableView does not need to be scrollable.
In this case you should disable scrolling for your UITable and it will work fine.
Generally you can combine "UI elements" such as UITableViews, UIScrollViews and UIViews however you like. But you need to be able to control them through UIViewControllers.

How do you build a 3 column layout of varying height images for the iphone

I need to create a screen that scrolls vertically - like the tableview but I need 3 columns and within those 3 columns I need to add images of varying height - so this will not fit into rows that a tableview can provide.
Should I create 3 tableviews and lay them out side by side - or something else. I think I could build this by simply positioning the images using coordinates but I wanted to benefit from methods that the table view can provide.
If you want the columns to act stuck together, so that they all scroll simultaneously, then I think best approach is to use UIScrollView with the images added in the correct placed "by hand." UITableView and friends is not built to handle non-lined up columns.
added If you do use a UIScrollView, and you have a large number of images you want to display (that is, the user can scroll for a long time), then it would be wise to recycle your UIImageView objects that are scrolled off the screen. This is what UITableView does with UITableViewCell objects, and that's why UITableView wins. You can win, too, if you code carefully.
Three table views would work, but in order to keep things neat and from the same datasource, I would consider using a subclassed UIPickerView and the UIPickerViewDelegate/UIPickerViewDataSource.
Particularly necessary methods:
// UIPickerViewDataSource
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:
// UIPickerViewDelegate
– pickerView:rowHeightForComponent:
- pickerView:viewForRow:forComponent:reusingView:
According to my opinion You should have to take three UITableView in xib file and take its IBOutlet then give each UITableView an unique tag and then implement UITableView's Delegate methods and in that Methods Check for Tag and then assign values.
Along With this, the other solution, you can also use UIPickerView and then implement UIPickerView's delegate methods also..
Happy Coding !!!

How To Replicate This User Interface Design?

I want to create a UI like the on in Mint.com app. Is it a UIScrollView with UITableView cells in it?
Notice how each block/cell has multiple data values in it.
This is all about customising the table view and table view cells. The best tutorial I've found is Cocoa with Love: Easy custom UITableView drawing. It's a good place to start.
This is a UITableView with UITableViewStyleGrouped and multiple sections. The spacing between sections appears to be increased from the default value.
The cell backgrounds have a slight gradient added to give them depth. Each section appears to have a different custom layout of labels, and, in the one case, a custom slider-like object. The object on the right is a standard UITableViewCellAccessoryDetailDisclosureButton.
You can achieve similar effects by subclassing UITableViewCell.

Insert ScrollView in TableView?

I have a TableView with one cell and I want to insert in this cell a lot of text so I think I'll need to use a ScrollView for scroll the text.
How can I insert? Is correct this method?
This is a help in the application, is correct use this modality?
Sorry but I'm a beginner and I don't have an iPhone or iPod, thanks!
While I concur with 7KV7's original comment, it doesn't look like there is need of a tableview in this scenario...
Just in case someone else happens upon this looking for an answer to the "Scrollview in a Tableview" question here are few clarifying points for the above comments.
The technical problem with having a tableview and a scrollview together on the same view is that UITableView is already a descendent of UIScrollView and if you attempt to handle both in the same view then you will end up with quite a mess with conflicting delegate messages.
As suggested by iPhonePgr, you can create a custom UITableViewCell. The first thought would be to let the UITableViewCell act as the delegate for it's own scroll view. The problem here is that the cell and it's contents could be discarded or reused at any moment as part of tableview's dequeue functionality.
So some ground rules to guide your implementation:
Whatever your solution, you're probably going to end up making a custom controller class, possibly derived from NSObject and implementing UIScrollViewDelegate.
The custom controller object acts as the mediator between the model object and the cell.
You will probably have an array or array-of-arrays that mirrors the model hierarchy driving the UITableView structure.
Because the cells can be discarded at any time you will have restore the scroll view state on cell initialization and preserve the state has part of handling your delegate actions or through a custom UITableViewCell implementing prepareForReuse.
Hopefully these points will come in useful to anyone who runs across this entry.
You need to create a custom cell by inheriting UITableViewCell and then add UIScrollView in the customcell. Then Use that cell in the Table view.
you can put your text in UITextView and add it as a subview in your UITableViewCell,because
UITextView is inherited from UIScrollView,
No need to add UIScrollView if you use UITextView
When you create UITableView you implement a number of delegate method which you can see by pressing the window key and then double clicking the UITableView delegate . In one of the methods you can set the cell height as per your requirement. By doing this your cell height can vary.
- (CGFloat)tableView:(UITableView *)resultTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 150;
}
As your table has a defined height, when the text in cell will be too much to contain into a scrollview will be automatically inserted.