Can UITableView be used to create a grid? - iphone

IS it possible to create the list of contacts or friends (Facebook for example),3 in a row ?
For example like 3 friends image with their name below in the first row and next three in the next row and goes on till the contacts are over. which can be selected for further process. Is there a API for this ??
Just like the home screen of iPhone or better example would be the application "Tap to chat"

Well there are a couple ways that you could do this, so I'm just going to throw out what makes sense to me. As far as I know there is no API specifically built for this.
How I would do this is to programmatically create my grid made of UIButtons. You would be storing these in an array of course, and I don't know if you have any ideas on if you would limit how many on a screen or per "page". Afterwards you could go through your array and change the background images of the buttons, effectively creating an Image Button(I don't know for sure, but something like this might already exist). It shouldn't be terribly hard, you just have to define for yourself what it is exactly that you want, how it interacts with its surrounds, etc.
Another option would be to create a very simple view that contains your image and your label, and the programatically create instances of this, though I don't think that adding button functionality would be as easy. It is still very possible I just don't know how to do it off the top of my head.

Use a UITableView with a custom cell with whatever you want in it, load those 4 images and names of the persons depending on the row number . To get the custom cell, create an IBOutlet to the cell and use this method.
[[NSBundle mainBundle] loadNibNamed:#"customCellView" owner:self options:nil];
To make a cell, make a new Nib/Xib file which is blank, make files owner the class with the cells, drag a UITableviewcell object out and put whatever objects you want on top of that view, set background as clear color and when you load the nib, enter all info into those images and labels. GL

Related

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.

Create a view like Tweetie's User Profile view

I'm just wondering if anyone has any idea on how you can create a view that looks like the user profile view in apps like Tweetie, where there are seemingly multiple tables with a couple of normal (straight up and down tables) and then two rows of six cells, which in Tweeties case have the number of followers, following etc.
I'm trying to make a similar view for my app, but can't seem to find out the best way to create it. Any tutorials, advice etc. would be appreciated.
Thanks.
P.S. Here's a picture of the view which I'm trying to recreate.
alt text http://technopedia.info/wp-content/uploads/2009/09/tweetie22.jpg
To get the same effect as Tweetie's split cell, create a custom cell and add a Segmented Control and create title and detail labels
It is a grouped tableview using custom cells. The image you show has two visible sections, and the top of a third. It also has a custom table header view. The second section has two cells built from four UILabels and a dividing line graphic in the middle. You can create this in a nib, or by hand.
You can even change the grey pin-stripe background if you want.

UIButton Game character selection to UIImageView animation

I am almost at the end of coding my kids educational application, woohoo!.
But... Im stuck on something.
When app loads i have my main view. It has 4 buttons for flipviews(each with ten views of content) and 4 buttons for character selection(an image that will follow you through every screen of content).
Problem is im unsure on how to link UIButton selection to UIImage display in multiple views. I want the user to choose a character button and then continue to the flipviews and in the views the image displayed should be the one that they have selected on the main view. So everytime they return to the main view they can change the character that will follow them around the app.
Any thoughts, help or code would be much appreciated!
Thank You
Alex
Make a new object, a subclass of UIImageView, which has a -setImage method. Once you set the image, then where ever you embed that object, it will display the same image. You could even have that subclass view have a score displayed next to it, or a name or other stats, so as you go from one screen to another, you have all that info follow you around with the image. No need to create labels in all the screens for global info like that.
In summary:
make a new subclass of UIView or UIImageView in Xcode using the New File... menu. You would do new UIView if you will have other items than just an image.
add methods that allow you to set the image, update text stats etc.
BONUS: you can make the class handle taps, so if a user taps the image, you could do something like provide help or run a cute little animation
embed that object in any screens you wish. Keep in mind that you can have that view be sized differently in each screen using transforms. Cool, no?
that's pretty much it!
Good luck!

Question regarding updating a UITableViewCell on the iPhone

I'm looking to do something simple such as drilling down on a particular UITableViewCell, which brings up a detail view controller. Within there, the user has the capability to change the attribute for the model underneath the cell. For instance, If I'm displaying a list of quotes, and a user clicks on a quote and favorites it in the child controller, I want to be able to display an image which was hidden now that it's favorited placed, a star perhaps. What's the easiest way to update one particular UITableViewCell in such as fashion? Is it best to reference the selected UITableViewCell into the child controller and couple them in such a fashion? How is something like this done?
Thanks.
It's probably easier to simply update your model object and then call [tableView reloadData];.
Then change your drawing code to account for the changes and display your hidden images or whatever.
setNeedsLayout did it for me.
For a complete code example have a look at the SQLite Books project on ADC.
To redraw a specific cell you should find its rectangle (rectForRowAtIndexPath) then call setNeedsDisplayInRect on the UITableView with this rectangle.

Toggling display of image in UITableViewCell

Depending on the result of a condition, I want to display a UIImageView in a table cell. Otherwise display UITableViewCellAccessoryCheckmark. I'd like to construct the cell in IB. The part I'm not sure of what to do with the UIImageView when I don't want it displayed. If I were constructing it all programmatically, I'd add the UIImageView as needed. But since it will be done in IB, the UIImageView is always there. Should the default be leave the cell alone (image displays), otherwise remove UIImageView and display UITableViewCellAccessoryCheckmark? If that is done, will I need a tag on UIImageView so it can be accessed and removed?
You can easily control the visibility of any control, including UIImageView. If you'd like to build things in IB then one solution is to add the controls you need, expose them as properties, and then hide the ones you don't want for a given cell.
E.g.
cell.image.hidden = YES;
When hidden they have no draw-overhead, and although your cell may have thousands of rows there will be very few actual cells, so it's a fairly efficient solution. Just remember that cells are reused if you call [tableView dequeueReusableCellWithIdentifier] (which you should do) so you'll have to explicitly show/hide control whose visibility may have been changed.
An alternative is to have cells with and without images and choose the correct one when adding data to your table. For cells that are similar managing two similar-yet-minorly-different assets would probably be a pain though.