iphone - dynamically loading a large mount of text and images - iphone

I am working on a iphone app, and I am just learning iphone app development for weeks, so I have some questions here : this app will load many posts from a remote server, and the post is consist of one text field, one image, and three buttons (good, bad and comment). There are thousands of posts on the server, so I thought the app will load three posts each time, and when the user scroll up the page, it will continue to load the previous post, and if the user scroll down the page, it will continue to load the next post. For being a newbie, I don't know what View is good for it, any advice is appreciated.
I have tried :
UIView + UIScrollView + Label / Image / Buttons (post)
UIView + UITableView + UITableViewCell (Label, image, buttons)
The first one is fine, and the second one, I really don't know how to make it in the second option..so what view pattern is good for this?

You are going to want to use a UITableView for almost all content in a list view. UITableView recycles is cells to save memory, so it can handle far more items than the just a bunch of uiviews in a scrollview I would start by reading up on the UITableview docs, and looking up some tutorials on custom UITableView cells.
here is the docs:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
personally I have a little library that I setup with custom UITableViewCell (via subclassing) to do this. You will also want to setup a model that works with the paging of your remote server (3 at a time you stated). So on the last post you will want to add a custom load more cell that when tapped, will get page 2 then lather,rinse,repeat. Any questions let me know.

You should go with the UITableView option. To tell if the user has scrolled to the bottom, look at this link.
Also, start the easy way. Just use the standard UITableViewCell and set the detailText label to your downloaded post title. Once you figure this out along with handling the scrolling and automatically downloading new posts then update the cell to handle images and additional content.

Related

How to lock a view as the user scrolls

I am new-ish to iphone development and I am trying to figure out how I can fix a view after it has reached a the top of the screen when a user scrolls a window. Then the view would unlock when the window is scrolled down again to go back to its original position. Ive seen this on on a few apps like instagram (with the user name separators).
Does this design pattern have a specific name?
An example (not iPhone though) can be seen on http://mashable.com/ -- Look at "The New Stuff", "The Next Big Thing", and "What's Hot" bar. See how it locks as you scroll down
My solution for you is
create a UITableView
create a UIView separately which will be used as fixed table header
setup the table's tableHeaderView property to conform the UIView's frame
as UITableView is inherited from UIScrollView you can rely on scrollViewDidScroll method in which I properly adjust my fixed header as Y coordinate changes when scrolling the table.
There can be other similar solution for this too but a strenght of this particular solution is that you can manipulate the fixed header's gui element throughout the scrolling easily.
An example is always better than writing down the details so I created for you (and hopefully for others here at SO) a sample project (of course quick'n dirty), which you can find here at github:
https://github.com/codedad/SO_Fixed_TableHeader_iOS
If I'm correct, you're trying to achieve something like the UITableView in the Contacts app?
It uses the sections of the UITableView for the sorted letters and displays them always on top.
Have a look a this question and create custom section headers.

UIScrollViews and Dynamically Creating Pages

I want to be able to dynamically populate UIScrollView. Like how it is done for row views in UITableView. I have a class that takes in some parameters and creates the respective view when it scrolls. Currently I have 8 views.
These 8 views have different background image, image and label according to the page number it is currently in. However the basic skeleton for this view is the same. What i am doing right now is in ViewDidLoad I am creating 8 views and add them as subviews and scroll over.
I don't want to do this. I want to create three views and the rest i want to populate when the user scrolls a page and then a page etc. How do i do this? ANy pointers/tutorial?
First of all you calculate the ContentSize for the scrollview (when you want to use the iPad in landscapemode with 8 pages then the width should be 1024*8 = 8192px and the height 768px).
Then you should implement the UIScrollView Delegate method:
scrollViewDidEndDecelerating:
In this Method you check on which page you currently are with the contentOffset property of the scrollview and start updating your left and right hidden views..
Hope this helps you a bit.
Check the two most recent WWDC videos for two excellent sessions regarding expert use of UIScrollViews. Additionally you can review a brief tutorial here, written by the well known cocoa expert, Matt Gallagher.

How to add action on the more scroll than data in UITableview iPhone?

I want to add some action or call a method when user scroll more than the data available in the UITableView. I mean in most of the iPhone app you have seen people add refresh while scrolling more than the cells available in the UITableview. In the same manner I also want to call a particular method or selector when user scroll more than the cell available in the table.
Provide me a some sample code or any tutorial if possible...
Edit:
"Hey I found the answer of my quesn by googling it. this link helped me. http://github.com/chpwn/PullToRefreshView

Format and draw text in UITableViewCell ala Twitterrific for iPhone

I would like to have formatted, clickable text and images inside a selected UITableViewCell. An example of the functionality I'm looking for can be seen in the iPhone Twitterrific app. When the user clicks on a cell, the cell is highlighted and the various links become highlighted and clickable.
I've seen the idea of using a UIWebView inside a UITableViewCell to handle formatting, but I'm unsure about this. Does that mean that every cell has to have it's own web view? I'm wondering about the expense and performance of such a method. Is there another way to get this functionality using Core Graphics?
I'm using custom drawing currently to draw my table view cells as described in atebit's blog post on fast scrolling.
Craig Hockenberry, author of Twitterrific, blogged about how he did that back in 2008:
http://furbo.org/2008/10/07/fancy-uilabels/
Basically, when the row is selected, he overlays UIButtons where the links are. It's imperfect, as sometimes the button won't fit in the same place the text does.
The first thing I would do is to checkout twitterific's old source code. And see if that version does what you are looking for.
I'm not sure how Hockenberry does it, but generally UIWebviews + UITableViewCells != fast scrolling.
My guess is that each cell does NOT contain a UIWebview until you click in it, when he quickly places a UIWebview in the cell to handle the text formatting. You then have a reusable UIWebview instance that you reuse but just change the content of repeatedly.

Nested UIScrollView-iPhone photos application

I have been facing the same nested UIScrollView problem for long time.I tried some open source codes like Scrolling madness ,three-20 and others but all fails finaly.I am trying to make a photo Viewer application same as iPhone.For that I have created the structure like this:-
1)one View controller.
2)on view of view controller one UIScrollView (i.e inner/parent scroll view) as a child.
3)on inner/parent scroll view number of child scroll views(i.e. outer/child scroll views) ,each represents one page of photos application.
4)On each scroll view one image View on which i am displaying my image.
So what I want is when user scrolls the outer scroll view it should scroll horizontally with all the child views so I will get the look and feel of paging in photos application.Also when user is on one specific image(i.e. child/outer scroll view) he should be able to zoom in/out,swipes and perform single/double tapping.I was able to make it work in sdk 2.1,but it dosnt work since sdk 3.0.Please tell me the idea behind your project.Means which scroll view you are subclassing ,in which view to detect touches.How this completely child - parent relation should be.
If possible provide any sample code also.
There is a WWDC session from 2010 that deals with this very issue.
Here's the short of it:
You need a single scroll view that is paginated and scrolls horizontally. Each "page" of that scroll view is another scroll view containing a photo.
First, it looks like you want to subclass UIScrollView? Every interaction method you need is provided for you in either the delegate callbacks or the touch methods. (Many of Apple's more advanced classes, such as UIScrollView, react poorly to subclassing.)
Second, it sounds like you have a first responder problem. IOW, your innermost scrollview isn't getting the first crack at the touch events.
Andrew
I also struggled with this for a long time trying samples you mentioned. I could finally figure it out with the samples provided by apple (iphone dev center).
http://developer.apple.com/iphone/library/samplecode/Scrolling/Introduction/Intro.html
http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Introduction/Intro.html
The first one is pretty basic and probably what u already have. The second one is all about zooming, etc. Just study these and the samples you already have, I think you will be able to figure it out. On specific topics just come back here search for answers or post another question.
EDIT: I forgot this one check out these examples by Andrey Tarantsov hosted on github. This is what you want... http://github.com/andreyvit/ScrollingMadness