Question regarding updating a UITableViewCell on the iPhone - 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.

Related

Can UITableView be used to create a grid?

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

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.

sticky selected cell in UITableView like the new twitter ipad app?

any idea how to have the selected cell in UITableView sticky and remain visible while scrolling? like how the twitter ipad app works. i would like it on my splitview's uitableview.
You are probably using a UITableViewController right? This automatically deselects a selected row. To avoid this, the best option would be to use a normal UIViewController with the protocols UITableViewDelegate and UITableViewDataSource.
Building from a comment Vince made on my previous answer (since deleted since it was more of an explanation of how long and how much effort a feature like this would take rather than an attempt at answering the question).
You could store the index path of a cell when it becomes selected, and then as the cell is about to scroll offscreen (you'll need some trickery to detect this) you could retrieve the cell view returned from cellForRowAtIndexPath and set a section header view to use this cell view.
This would be a pretty monstrous hack though, and you'd need to find a way to elegantly split the table into sections in order to use the section header.
I wouldn't recommend this approach, although its a step in the right direction.

UITableView and UITableCellView, how does this work with core plot?

I'm very new to iPhone programming, and I'm currently following tutos to understand the whole thing. I've been able to do what I needed (retrive data from a JSON http server, parse them with YAJL and plot the data in core plot). I have done this in a "simple" view where I have added a UILayerHostingView as requested by core-plot.
I am now trying to follow this tuto: http://blogs.remobjects.com/blogs/mh/2010/01/26/p973 but I am missing the first part regarding the views...
My understanding is that I need to create a view with a UITableView first. Then add a UITableCellView to make the first cell be able to contain the graph ? Is this right ? Where does the method "(id)initWithStyle:(UITableViewCellStyle)style" come from ?
For my needs, only the first cell needs to contain a graph, I will put some other info in the other cells.
As for now, I have created a new GraphListViewController, in the corresponding view I have added a listview but I do not see any auto generated methods regading cell customisation ? Do I need to implements DataSource in this controller and manually add some customisation methods ? Do I need to add a UITagbleViewCell to this UITableViewTable within IB ?
Hope I am not getting to confusing...
Thanks a lot for your help,
Best Regards,
Luc
To start with, create a new file ...
Cocoa Touch Class -> UIViewController subclass
and click the UITableViewController subclass checkbox. This will do all the tableview work for you. You can now open the xib file and change all the properties that you want for this.
Once this is done you need to populate the cells within the table. The first thing you need to do is to tell the controller how many cells to display. For this update the numberOfRowsInSection: method to return how many you want.
The next part is where you want to create the cell and is done mainly in the cellForRowAtIndexPath and for this I'm gonna redirect you to the following good tutorial on adding custom cells.
http://iphonedevelopment.blogspot.com/2009/09/table-view-cells-in-interface-builder.html
This explains a bit of the 'magic' that happens
Hope this helps
Liam

Creating UITableViewCell with add photo button like in Contacts app

When you add a new contact, the first row contains the add photo button and the x co-ordinate of start of the cell is set to some value which is greater than the rest of the cells. How can this photo button be added and the cell frame can be changed?
Thanks!
They use a custom cell to achieve this. This custom cell has the picture-like control on the left and mimics a table cell next to it. It's not something that comes out of the box.
You can't set the x co-ordinate of a cell either, you can set the indentation on the other hand.
Edit: come to think about it, they probably use a custom table header instead of a custom cell. You certainly will find the headerfooter sample on developer.apple.com helpful.
Link: https://developer.apple.com/library/archive/samplecode/HeaderFooter/Introduction/Intro.html
I am more inclined to believe that they use tableHeaderView property.
Sure you can achieve the effect with custom cell.
But with header its pretty simple! I have done the same in few places!