Format and draw text in UITableViewCell ala Twitterrific for iPhone - 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.

Related

iphone - dynamically loading a large mount of text and images

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.

Drawing UITableViewCells for fast scrolling, but what about links?

I read this great article from Twitter about fast scrolling and how to draw cells. I have implemented this fine, but now the hard part - the links in the tweet. Is there any way to use this approach and draw links in the cell as well? I know this is possible using a number of different label extensions, but the article specifically mentions not using UILabels and UIImageViews. If I have to use UILabels to achieve this that's fine. I just want to be sure this is the only way. Thanks.
Because detection of touch events is done in UIViews, one method might be to override the UITapGestureRecognizer on the UITableViewCell, and in the action it fires upon a touch, check to see if the tap is within the bounds of your link that was drawn. If it was, handle it accordingly, if not, handle it as a cell selection.
If you don't need cell selection, you could always have selection of a table cell perform the action you want for the link as well.

How do I make an editable detail view on the iPhone with a grouped UITableView?

I want to make a grouped TableView similar to the Apple iPhone contacts application.
I need a lot of standard fields which can be edited, but I would only like them editable once the edit button in the navbar is clicked.
This has been bothering me forever that I could not find a good tutorial.
Thanks in advance.
This is not easy. I just built the same thing because there is nothing available from Apple. I ended up creating a single table cell with a UILabel and a UIView on it. The UILabel is for when the cell is in read mode, and the UIView is for editing. The UIView contains a number of UITextFields. These are the individual fields. I also had to implement drawing code to draw the lines between the fields. Then I had to come up with the code to pass in an address object, load it into the fields, format the text for the label, switch in and out of editing mode (with animation), and finally handling saving of changes and canceling. As yet it doesn't handle tapping the address type to select that from a popup list, but I have most of the code in place for the rest.
This could have been done using individual table view cells for each field. But then you can't select the whole thing the way it does in contacts and adding and deleting addresses becomes trickier.

Mimic ABNewPersonViewController UI

I'd like to replicate the iOS 4.x ABNewPersonViewController UI layout (see link text) in a custom view but I'm unsure about the best way to achieve this. I was thinking of a single grouped UITableView, but what about the first section? How do I achieve the smaller cells (first,last,company)? And finally the "add photo canvas" is it just a sub UIView with a background image for the shadow and the rounded border or can this be done programmatically?
Many thanks in advance!
your idea about a single grouped UITableView could work. The way to get the smaller cells as well as the photo cell would be to subclass UITableViewCell and create it like that. and yes the photo canvus is just a custom UIView added on top of the UITableView. I'm not sure i see the point of rolling your own here, but thats how i'd start. Also i think i recall seeing a tutorial on how to build this page..try googling for it.

Achieving dynamically growing TextView inside UITableView

I am working on fitting a UITextView inside a UITableView. My table is grouped style with only one section and one row. I've looked through various previous questions but I am unable to get this idea working. I want the result to be the same as the "notes" section in the Calendar app on iPad. And Apple has done the same thing in the contacts app as well for notes. Do I need to use view animations to make the tableView row keep growing dynamically as and when more and more text is typed into the textView? What is the correct overall approach to make this idea work? Any pointers would be greatly appreciated. I get the points on how to resize the textview depending on text size and how to modify the height of the table row. But how do I make these work together to give it a dynamic animated feel like in the Apple apps?
Also another thing I noticed is that the cursor always lands at the beginning of the text view due to which the text gets overwritten and ugly on appending. Is there any method to get the cursor to go to next to the last character in the textview when I tap on it again while some text already exists inside it?
Thanks
You can refer to this Post for dynamically growing your uitableviewcell.
This library can help you grow UITextView with auto layout
https://github.com/MatejBalantic/MBAutoGrowingTextView
You can set-up the hooks (either in the library or you set-up the UITextView delegate) to make sure size of the table view cell get's recalculated based on the new UITextView size each time content of the text view is changed.