How do I initialize a UITableView in the middle of the table - iphone

How can I initialize a UITableView so that it starts off showing something (of my choosing) in the middle of the table, rather than what is at the top? I want to have a certain cell in the table always start at the top of the screen, so you could scroll up or down from there.

You can scroll to a certain cell by sending - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated to the table view.
As you have described you want the cell of your choosing to appear "in the middle of the table", so you should use UITableViewScrollPositionMiddle for the scrollPosition argument.
If you do this as soon right after your table is initialized or as soon as your view loads with the animated argument set to NO then the table view will appear with your cell in the middle, just as you've described.
You also write: "I want to have a certain cell in the table always start at the top of the screen".
By instead choosing that cell and the scrollPosition UITableViewScrollPositionTop you can make that cell be at the top of your table view.

Related

Check for section index titles from table view cell

I have subclassed UITableViewCell and I need to draw my own disclosure indicator. The position of the disclosure indicator depends on whether or not the table view has section index titles set (the "scroll bar", typically the alphabet).
Does anyone know of a way to check if the table view shows section index titles from the cell?
Checking this from the UITableViewCell subclass would require a big deal of coupling with the UITableView class, so I suggest you take an alternate route - add a BOOL variable which you set in the cellForRowAtIndexPath: function and then call a function on your cell that will draw the disclosure indicator according to the value of the variable.

pop up detail view out of tableviewcell

I am working on a app where I want to expand a tableviewcell to cover almost all the screen with animation when it is selected by user. I am looking to create a uiview on the tableviewcell and expend it to cover major portion of the screen when user selects the row.
The main problem I am having is to get the frame from where my pop up view will start expending. How will I get the frame of the row which is touched?
Thanks
Pankaj
Is it crucial that the cell should not reposition?
If not ( i am guessing not, as you are anyway planning to cover whole screen):
When the cell is selected, scroll the cell to top (using scrollToRowAtIndexPath) and either insert your custom view to cell's contentView or modify its parameters if its already there with different opacity/size etc
Use UITableView function to get the rect for the row by passing the its NSIndexPath.
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewCell subview (left side)

Is it possible to implement a subview of a UITableViewCell on the left side of the cell that crossfades when the table enters the editing mode?
Another problem I face is that the bounds of the cell.textLabel are read-only. Is it possible to use some sort of inset for that label? (Because I, like mentioned above, want to use a View on the left side)
Edit: How do I perform an action (in this case fade a subview) when the whole table enters editingmode? (Not through a swipe over a cell). The reason why I want to implement this is because the tableview shows the "-" button on the left side of the cells if it is in editingmode. (I want to show my own button on the left side of the cells if editing=NO, fade it out if editing=YES and show it again if the tableView leaves editingmode (editing=NO))
A first thought directs me to something like this:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if(editing) {
//fade out my own button
} else {
//show my own button
}
}
But I would have to loop through all the cells and I think this leads to a substantial performance worsening. What do you think?
You want to set the Editing Accessory View of a UITableViewCell. See the editingAccessoryView property for information on this. More information can be found in the Customizing Cells section of the TableView Programming Guide.
The label within the content view of a table view cell is read-only so you can not reassign it but its properties are mutable. You can actually move the label around within the bounds of the table view cell. It's probably confusing to grasp, but have a look at the Characteristics of Cell Objects section of the Table View Programming Guide. In it, the bounding boxes for each of the nested views are shown (not all of them are always visible). For your purposes, a good exercise would be to set the background color of each subview of a UITableViewCell to a different color and then try to adjust the sizes of them. Doing so and understanding what's going on will probably let you achieve the end-result that you desire.
In the end I created a custom UILabel that I used instead of the default UITableView textLabel and added a custom button on the left side. In the setEditing method I fade this button in/out.

How to decrease width of table view cells for iphone

I'm trying to create a grouped table view with two sections. For the first section I would like the width to be only half the screen. For the second section it would be the standard width. Also, next to the first section I would like to put a button.
How is this done?
Thanks!
To put a button in a section what I've done in the past is create a section that has no rows in it. Then, I respond to the - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method with a view that contains a button that is rigged to whatever delegate I need. This will give you the appearance of having a button sitting in a section with no data. This is how buttons appear in the Contacts view/edit screens in the stock iPhone apps.
Table view sections are fixed with to the size of the screen. If you want the individual cells to appear narrower in one section and wider in another, then you can control the size of the view itself with the data source delegate, though you might have to set the background of the table view to transparent so users can actually see the smaller view on top of the table view.

Why does the last row of my tableview not align to the bottom of the screen

I have a view which consists of a tableview and a navigation bar. For my tableview I have implemented a 'Load more' row which will load current + pagesize every time it is clicked
The way the loading works is very simple, every time it is clicked I just request the amount of rows I want to display e.g. 5, 10, 15 and so on. This request populates an array and I call
[self.tableView reloadData]
The issue I am experiencing is that when I go to the tableview the first time, it correctly loads and displays the tableview. However, if I 'Load more' it returns the correct amount and displays the correct number of cells but the last cell will not fit properly at the bottom of the screen, about 1/2 of it (or roughly the size of the navigation bar of the cell) appears below the bottom of the screen.
I thought it was sufficient to just tell the tableview to reload itself. Do I need to use
[self.tableView insertRowsAtIndexPaths ...]
to do this.
Check the frame of your tableview...its probably too big and therefore its getting cut off
After you load more, does your scroll bar stop at the bottom of your table, the way it should work, or does it look like the scrollbar scrolls past the bottom of the table? If the scrollbar scrolls past the bottom of the table, then Daniel is right and your tableView's frame is somehow changing and becoming too large to fit on screen. If the scrollbar stops where it should, then your tableView's frame is fine, but for whatever reason the tableView is not correctly calculating it's own contentSize.
Do you implement this method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
in your tableview's delegate? If so, my guess is you are not specifying the correct size of your table cells. Is the load more cell the same size your other cells?
make sure that your tableview isn't autoresizing...