How to make an never ending UITableView? - iphone

I have some options in an UITableView and want that the user can scroll forever. When the end is reached, I want to append the begginning so the user can continue to scroll.
How would I do that?

In tableView:numberOfRowsInSection: return some huge number, and act accordingly in tableView:cellForRowAtIndexPath: by returning same cells over and over.
You can also have limited number of rows, and at the end show a different cell - containing a button for user which he can use to append new rows. When that button is clicked you simply call [tableView reloadData] and provide more rows in table's data source.
Aren't you by any chance misusing the table-view for something it doesn't fit that well ? Maybe you would be better off using just a UIScrollView and reposition subviews as user scrolls over.

I think the only problem is how to trick in the method numberOfRows:. One possible solution is to return some big number here, for example, 10 000. Then, you set up a correct cellForRowAtIndexPath: to return based on your data's number modulo. For example, if you have 100 data entity, then you have to get the indexPath.row % 100

Related

Separate buttons in UITable without custom cell

Is it possible to have a UITable with cells that are all the same, each containing buttons that only effect that cell (based on indexPath.row I'm guessing), without having to make a custom cell?
I too need this, but I have a custom cell.
#kaylaGalway your method sounds like it could work for me, could you elaborate? As I have been searching for this answer for hours now (Swift 3)
You can design your table cells freely. It is possible to have a different cell for each and every row within the very same table.
When you have matching cell types for each row you can also add buttons (one or more) in these rows. They can also point to the very same function. With a clever usage of the 'tag' you can identify each individual button. Using the Indexpath.row you can naturally also identify the row in the table.

Multiple rows insert auto insert in edit mode with UITextFields, similar to contacts phone/email

I am trying to recreate functionality of similar to adding/editing phone numbers or emails in the contact editing on the iPhone.
I always have an empty row with placeholder text available. In edit mode (push of a button on toolbar) I un-hide UITextField. In 'editing changed' callback I insert a new row into the section, again similar to iPhone contact editing view.
However, after the insert when I start modifying 2nd row (3rd row is inserted as expected) the value of the 1st row text field is cleared to the placeholder value.
I have read somewhere that I would need to store the text field value in row 1, at the time of 2nd row insertion, and on end editing (I assume) otherwise it would be lost? This seems quite strange to me and I was wondering if this is the only way? At what point would I go back to restore it? This of course keeps repeating as I insert a new row and modify the last row's value values in all the rows prior are being cleared.
Can anyone point me to an example of similar to contact editing functionality? If I would change the way rows are inserted by having the last row always be a "+ Add Value" row, would that help? I would not think so.
Also, It would be nice if I could change style of the 1st row from UITableViewCellEditingStyleNone to UITableViewCellEditingStyleDelete, but no matter what i have attempted including toggling editing NO/YES in the middle setting all visible rows to react to ignore transitions I can not get it to work, to have all but last row with UITableViewCellEditingStyleDelete. So I thought ok fine let me have the initial row not able to delete (not what I wanted, but I can live with it).
Please confirm, but I am guessing from reading farther that scrolling rows out of view would result in the same problem, so on textFieldDidEndEditing as well as possibly on each insert in my case, needs to be handled to store "new" data in the corresponding entry of the Data storage array for each row.
However, in my case without scroll I would probably need to do:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimat....
for all rows in the section being modified and possibly all visible rows. Confirmation are greatly appreciated.
Why reuse at all in your case?
If all the rows are on the screen at all times just create a new UITableViewCell for each.
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
configure content to go on it...
[cell.contentView addSubview:WHATEVER_YOU_CREATED];
[cell.contentView sizeToFit];
return cell;
Reusing cells is a way for those that have many rows to reuse the ones no longer visible to conserve resources.

How Expand the table view cells?

I want to know that how the row size will increase and expanded when click on one row..
Please give me some suggestion
If it goes for all rows:
Use a variable cellSize for creating every cell, and when the table gets initially created, use that cellSize.
In the didSelectRowAtIndexPath, increase the value of that cellSize and do a [tableview reloaddata]. That should do the trick...
If it goes for one row, you should check when creating the rows if the value in the array (the array you want to view in the table) is the correct value, and if so, increase the cellSize, if not, use the original cellSize. Not sure if this last part works, but I can't really think of anything why it wouldn't. Try it out and let me know!

UITableView reusable cells problem

I have a UITableView and its data gets refreshed from a server connection. For the UITableViewcell, I have layout some labels across the row. So it can consider as a grid with UILabels(total no of labels = table rows * table columns).
When the data gets refreshed I have added an animation for the UILabel to highlight the table cell update.(Labels background color changes for about 0.5 seconds and restore to the previous background color). There I compare the old value with new value and I added the animation with comparing those. It works fine.
My problem is when I scroll the table, because of the reusable cells the labels are getting animated.(although the corresponding values are not change). Anyone have an idea to how to avoid this issue? thanks.
It sounds like you're calling reloadData and animating in tableView:cellForRowAtIndexPath:. Don't do this. There's no guarantee that UITableView will reuse the same cell (it sounds like it does, but it's unwise to rely on this, and I'm pretty sure it doesn't for reloadRowsAtIndexPath:withRowAnimation:). It will do the wrong thing if you remove a row, for example.
You can use -[UITableView visibleCells] to get an array of the currently visible cells. Loop over the array and use a custom method to tell each cell to reload with animation.

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