Subclass UItableViewCell with multiple Legends and Labels - iphone

I Know this question has been asked a lot in a hundred different ways (and thats just on this site). But I'm struggling to put all the pieces together.
I would like each UITableViewCell to look like this:
It has multple legends and several fields. The legends are static and wont change but the corressponding labels will vary in width and height. Therefore so will the cells. I need the legends to always align with their labels.
I have tried to do this using the Interface Builder but don't really understand the autoresizing. Though I'm happy to do this in code.
Does anybody know how to do this or at least have some good links to tutorials, source code etc?

Putting a full table view inside a cell is crazytalk. Maybe somebody got it to actually run - that doesn't mean it's best practice or good practice.
I will answer your question after making one very down to earth suggestion. Please consider following Apple's guidelines by putting just a summary of each event in your cells for this table, and allow the user to push down to another view controller to see the details of a particular event. This will probably help you develop your app faster and get to market, then you can think about advanced stuff like customizing individual cell heights at runtime.
That being said, if you insist on putting all your eggs in this basket, then I think you will need to implement your table view cell in IB, note the details for all of your content label frame dimensions, then, at run time, use one of NSString's sizeWithFont:constrainedToSize: methods to determine how big your labels will be. Make them that big. Then from that data compute the height of your cell, and return that value from your table view's tableView:heightForRowAtIndexPath:. This is how I implemented this functionality in an app a few years back. (Frankly I'm not sure that it's still working.) There may be some better methods for figuring out the label size in CoreText, I haven't looked.
A better bet will be to constrain yourself to a limit on the length of text you can put in each label. Then you can just define the labels statically and use a constant-sized cell. Putting it together in IB isn't tough. Just lay everything out, and make sure that you create an IBOutlet and XCode/IB connection for each object you want to manipulate in code.
Good luck!

Add a tableview to each UITableViewCell. The outer tableView will be responsible for holding all your cells and each cell will be a Event with cells for each parameter.
This tutorial will give you insight on how to set that up.
http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/

Related

How can I make my custom UITableViewCells as fast as possible?

I'm creating custom UITableViewCells, and I'd like to make them in a way that allows the table view's scrolling to be as smooth as possible. In their current state, with a custom background image on each cell using the cell's backgroundView property, scrolling is is still fairly smooth.
But my question is, how can I add content to the cell and maintain this? The cells are fairly different from each other -- one may have a single label, another may have two labels and an icon, and another may have a bunch of other controls.
I've found that using unique cell identifiers for non-similar rows makes the overall experience laggy, so I need a method that allows me to use the same cell identifier and have very different cells.
Should I be using an XIB for this? If not, how should my subclass function? I was thinking of adding all of the controls to the cell, and only hiding/using the ones necessary at the time. Is there a cleaner way?

How to make a UITable with columns?

I was wondering how to make a UITable have columns. Or, is there a better way to create an actual table that looks like a grid. I want to have 3 columns. How can I do this?
The UITableView doesn't have support for more than one column. However, this can be easily fixed if you create your own custom UITableViewCell-s. You would need to stash three different views into the cell and then add whatever you want in them.
If you don't mind the fact that you cannot scroll horizontally you can just use a custom UITableViewCell to give the illusion of columns. If you really want columns (like a spreadsheet) you need to subclass UIScrollView and implement UITableView-like view caching. Luckily Apple has some sample code which shows how to do this, see TiledScrollView.m

Any ideas on how to make a UIPickerView from scratch?

I've decided that I don't want to ever use UIPickerView again... it's completely inflexible in terms of functionality, design, and size (height). It also occasionally gets stuck between rows, and the delay that occurs between letting go of a wheel and when the delegate method is fired indicating that a new row has been selected (because of the "settling in" animation) has caused lots of problems in the context of the apps I've been working on.
That being said, the user-friendly aspects of UIPickerView are good, and I'd like to try to replicate it. I've tried to research different ways that this might be done, but without much success. Does anyone have any ideas as to what would be involved to make something similar from scratch?
I was trying to get a UITableView subclass to behave in such a way that whatever cell was currently in the middle of the table (it would change while dragging, etc.) would change its background colour to something different implying that it was "selected". As soon as the table was dragged such that the "selected" cell was no longer in the middle, the cell would go back to normal and the new middle cell would change colour. So this would be like UIPickerView in a sense that you don't have to tap on a cell; instead you just drag to have one selected by default.
I figured it should have been easy enough to intercept the "touchesMoved" method of UITableView and add some code that looped through all currently viewable cells in the table, checking to see if their frames overlapped the center point of the table, and changing their appearance accordingly (plus sending a notification to other classes as needed to indicate the "selection" change). Unfortunately, I can't get this to work, as the "touchesMoved" method doesn't get called when I drag the table. Am I missing something obvious?
Any ideas or suggestions would be very much appreciated at this point... I made an app that relied heavily on UIPickerView objects, and because of the problems I've run into with them, I'll have to abandon it unless I can figure out a way to make this work.
Thanks very much,
Chris
Remember that a UITableView is a subclass of a UIScrollView, and the UITableViewDelegate gets all the UIScrollViewDelegate method calls too. scrollViewDidScroll: sounds like it would easily fit the bill for knowing when the table view was scrolled.
As for finding which row is in the middle of the view, just use indexPathForRowAtPoint:.

How to implement UITableView with multiple columns and sideways scrolling

I'm thinking about how I could achieve this kind of UITableView: http://snapplr.com/c1x5
So it has multiple (separately selectable) columns in it which also differ in width. Apart from that it can also scroll sideways to see programs which broadcast later on the day.
Now, I'd like to know how you would implement this kind of feature. A scrollview wouldn't be enough, it has to somehow load newer data. And of course you need to be able to know what column in the cell has been selected.
Hope to hear some thoughts.
That is a custom view.
It's possible it could be a table view, with heavily customised cells, but that would have been a hell of a lot of work to get it scroll horizontally too.
It's more likely that it's a scroll view with a custom grid view type class that have support for arbitrary grid cell widths...
I'm sure if you write something like this you'll have a lot of interested people.
I just updated MDSpreadView, which is basically a UITableView that works both horizontally and vertically, floating headers and all, with an API very similar to UITableView.

How do I create a TableView like in network Settings App on the iphone?

How do i make such a Table view? So if I turn on the switch, 2 cells should be added.
I've already tried
[tableView numberForRowsInSection:6];
[tableView reloadData];
but this doesn't work as expected :(
any ideas?
The best thing would be 2 sections the first section contains 5 cells, the second section contains one cell with a switch turned off and if the Switch has changed 2 cells will be added to section 2.(Added with an animation :))
mhh..
Thanks in advance, I'm very excited on every answer :)
Where did you pull this -numberForRowsInSection: method from? As far as I (and the documentation) know, it doesn't exist and has never existed as a method of UITableView. Guessing is going to get you nowhere, much less inventing methods from thin air.
Perhaps you should review some tutorials that cover the basics of using UITableView before you attempt this. I doubt someone is going to take the time to write you a full class to do this and put it in an answer, and you'll be much better off in the long run if you don't simply try to copy/paste code that you don't understand. There exists much documentation and examples that cover UITableView, and that's just considering what's available from Apple - UITableView is such a frequently used class that searching Google for something like "UITableView tutorial" is going to give you pages and pages of results.
I will give you a quick overview of what you would need to do, though:
1. Of course, you can start with the UITableViewController template in Xcode and start customizing it to fit your requirements...two sections, however many rows per section, etc, determining that based on some model-level objects if necessary.
You'll need to either create a custom UITableViewCell subclass or customize the default UITableViewCell layout a good bit (at least by adding a UISwitch subview) when you create new cell objects in tableView:cellForRowAtIndexPath:.
The UISwitch should be configured to send a message to your view controller when the switch's value changes using -[UIControl addTarget:action:forControlEvents:] for the UIControlEventValueChanged event.
In your implementation of the action method for this switch value change, you'll need to implement logic to determine whether rows should be added or subtracted, and then actually add or subtract the rows. You can use beginUpdates/endUpdates, insertRowsAtIndexPaths:withRowAnimation: and deleteRowsAtIndexPaths:withRowAnimation: to have the nice smooth row animation behavior instead of simply calling reloadData.