Naming Sections in Grouped UITableView - iphone

I have a grouped table view with two sections.. I have an NSArray which pulls in 5 section titles from a database, I want the first section in the uitableview to have four rows, whose titles are set to the first four elements in the NSArray and the second section to contain a whose title is set to the last element in the array, how is this possible?

Everything depends on what you return from your data source's tableView:numberOfRowsInSection: and numberOfSectionsInTableView: methods. Sounds like you want 2 sections, with 4 rows in the first and 1 in the second — you can do this by checking indexPath.section in numberOfRowsInSection: and returning the appropriate value. Then in tableView:cellForRowAtIndexPath:, you can use indexPath.section+indexPath.row to get the overall row number.

Related

Increase number of clicks on each collection view cell and display them in each cell

I have a UICollectionView displaying a UITextField inside each row. The number of rows may be dynamic, and what I want is to display the number of times the specific cell is being clicked and display count on each textfield simultaneously.
I have tried setting a variable for number of clicks and I've tracked each index-path so the count is increased but,
I'm unable to increase their own value on their own cell.
Use this right after you increment the variable:
collectionView.reloadItemsAtIndexPaths(indexPath)
I only have this logic maybe it would help you a little bit, I may
provide you with code after I convert my logic to code.
If you have already stored the number of clicks then you must make an array to append the cell which has been clicked and filter the indexpath.row that you will append in this array which you'll get in didSelectRowAt.
You need to filter them such that, if the selected cell has previously been appended in the array it needs to be removed from that index and appended to the last index of the same array.
So that you can access the array of your clicked row, to show them on each of their cells textfield.

Using xcode 6.4, Hide/Unhide rows in TableView sections when there are many sections

I have a Table with many sections and each section also has rows. How can I hide/unhide the rows per section? the table will be easier to manage if the user only sees sections and can 'tap' the section to see the row selections.
Implement tableView(_, numberOfRowsInSection) in the table view's data source to return either 0 (to hide them) or the actual value. Then, in the table view's delegate, implement tableView(_:viewForHeaderInSection:) to return a view that listens for taps.

How To customize different rows in UITableView

I want to create a page in iphone sdk which looks same as flight search result
problem is that each there are different number of stops some has 2 stops some has 1 etc. and not only leave flight detail but return flight detail can also be asked.
It must sorted on the basis of charges.
I am not getting from where I start
I make 3 custom cells
showing source n destination detail
the flight detail
to make separator between leave n return results
this is demo i have tried with fixed value! [1 row a SimpleTableIdentifier(background color not able to set) 2 and 3 row are 2 different CustemCell, there is separator custom cell too]
but I think i make it complex unnecessary
any tips and help will be apprecited thanks in advance.
Go like this make three customCell one for each of your three category
cell structure to show source and destination detail
cell structure to show flight detail
cell structure to make seperator
Now your UITableView will be a grouped tableView with numberOfSections = number to total flight you have to show
Each section will have three rows (if it has all three information available) else you can reduce the number of rows in any section by delegate method of UITableView named numberOfRowsInSection.
Try not to forget to give all different custom cells other dequeueReusableCellWithIdentifier's for re-usability.

Can I drag sections in tableview as I can do it with rows?

I use
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
toIndexPath:(NSIndexPath *)destinationIndexPath{
}
method for dragging and dropping rows within and across sections. Can I perform drags with sections as well?
It's probably conceptually (as well as technically) simpler to step back a level to a table view where each row corresponds to the sections of the table you want to re-order. Maybe you could invoke this with a "re-order sections" button, show the section-table-view, re-order, then impose that re-ordering on the detail table view.
I think if you try to do it all inside a single table, you're going to frustrate yourself and your users. My 2 cents.
-Mike
Old question, I know, but I just implemented something that does this myself so I wanted to share the answer in case it helps others who stumble across this.
My basic approach was to add a row representing the section to the top of each section. I also added a "Add a new section" row with editing style of UITableViewCellEditingStyleInsert at the end of each section to allow creation of new sections directly within the view. So, for each section the rows were like:
Row 0 = Section row (visually distinguished by setting different
background color)
Rows 1 to x = normal data rows
Row x+1 = "Add a new section"
(I have a couple of simple methods to translate between "edit mode indexPath" and "real data indexPath".)
For moving sections, the proposed move is checked in the UITableViewDelegate Protocol method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: to ensure that the section row has moved "far enough" (above or below another section row). The returned indexPath is clipped to either just above or just below the nearest section row (depending on if moving up or down) to give the user a visual indication of where it will be moved.
In tableView:moveRowAtIndexPath:toIndexPath: the section change is made in the data source, then a reloadData message is sent to the tableView to display the change. reloadData is used instead of moveSection:toSection: because with the latter, the data source and display would be out of sync due to the row move and would cause an exception.

TableView in iPhone

I have a very long string that i need to display in the first row of the table view. The string is like
"1|123|Try|Bank Of America|11/06/2007|20,000.00"
where | is the tokenizer.
Now I take the first token ie 1 and append String "\n", so that 123 is displayed in the next line of the row of table view, but I can just display 1 and 123 in the first row of the table view. I can't display the other values.
See the case is, the result string is the information of a transaction, similarly there are many more transactions that i will be displaying in the table view. But the rows in table are not big enough to display the entire information.
If I read your question correctly you want to increase the height of the row?
If so, you can use the delegate:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
To accomplish this the better way is to follow the customization of cell.You can increase the height of row using delegate method tableView:heightForRowAtIndexPath.
(you need to return the height as return 55). Then you can add a label to cell and then add text to label with specifying the number of lines in label according to your requirement.
Sounds like you are using the standard UITableViewCell. I'd recommend using a custom tableViewCell with a UILabel so you can control how the truncation is handled and how many lines you can have, etc. You still have to use #rein's suggestion of resizing the rows.
You're going to have alter the height of the tableview cell depending on how many lines of data you want to display in each row. You will need to write a UITableViewDelegate's tableView:heightForRowAtIndexPath: to return the correct row height for each row.
Calculating the row height will prove tricky if the number of lines of text changes each time or if the font size changes.
You might want to rethink your design. Tableviews are not intended to display a large amount of information. Instead, they are intended to display information that more or less fits on one line. You should consider a design that displays one line of information that will identify the record and then provide a detail view to show all the data in the record.
For example, in the contacts tableview, you have a tableview that shows the name of the contact and then a a detail view that shows the address, phone#, email etc.
You can try
[cell.textLabel setNumberOfLines:5];
This would in combination with the heightForRowAtIndexPath will give you what you are after.
Been asked many times. See:
How do I wrap text in a UITableViewCell without a custom cell
Setting variable UITableViewCell height