I am trying to implement a horizontal scrolling UITableView on the iPad, just like the Raombi app, in which the left panel sticks to its own place when scrolling horizontally. Moreover the UITableView is based on a columnar approach so it should scroll seamlessly together.
I have no idea how to start in order to fulfil these requirements.
Here is the screenshot of the desired functionality.
In viewDidLoad just rotate your table to 90 degree and load cells by rotating every cells to -90 degree. Consider your first column as table header and rest every column as table cell.
Go through below.Add this in viewDidLoad
self.tblDetail.transform = CGAffineTransformMakeRotation(-M_PI_2);
And below lines in cellForRowAtIndexPath method
if(!cell){
UIViewController *controller=[[UIViewController alloc] initWithNibName:CellIdentifier bundle:nil];
cell=(MyCustomCell *)controller.view;
cell.transform = CGAffineTransformMakeRotation(M_PI_2);
}
Apart from that design your header and cell in different nib files. For header just do as below:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
MyHeaderView *myView = //Your view instantiation code
myView.transform = CGAffineTransformMakeRotation(M_PI_2);
return myView;
}
I think this view is too complex to show in the one screen and generate it.
Since the iphone size is too less to display above view easily. Still if the following links useful to you please use it and get back to me.
I hope the following links are useful to you.
1)
http://code4app.net/ios/Multiple-Columns-TableView/4f901ef306f6e7123a000000
2)
http://code4app.net/ios/XCMultiSortTableView/520881e56803fa991f000000
3)
http://code4app.net/ios/RATreeView/524e2f896803fa6e31000001
4)
http://code4app.net/ios/Multiple-columns-Table/51e4dd116803fa1026000000
5)
http://code4app.net/ios/Static-column-table/50fe649d6803fa7b65000001
Related
I know how to add a shadow around UIViews and even to animate them when the views bounds change. However I've come across a view that is a little more tricky it seems. UITableView
Adding a shadow around this view is easy enough and even going by this example: Adding drop shadow to UITableView
It works well. However my problem is that I need the shadow to go around the last cell in the UITableView and not it's bounds. So, top, sides and bottom would be the last cell in the UITableView.
Thinking about how it'd work leaves me to believe there is a better solution. Maybe if I was able to adjust the UitableViews frame based on the number of cells? However the cells are dynamic and I don't know their heights until runtime.
Any suggestions would greatly be appreciated.
Thanks!
something like...
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
// last row
cell.layer.shadowOpacity = 0.5;
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
cell.layer.masksToBounds = NO;
}
}
Only one option for your requirement :
1) Add shadow for top, left and right of UITableView.
2) Add shadow to bottom of last UITableViewCell. For this you might need to increase height of last cell of UITableView;
I make one UITableView Controller had static cell. And I set number of rows 3 in Storyboard. But rows does not set 3, just be made more and more like this screen shot. I don't touch any programatic code. Did I have to make it programmatically?
That's the normal behavior of a UITableView. Even though you only have 3 rows, the view itself extends to the bottom, and it shows where the cells would be if you had data in them. To fix, do one of two things: customize the UITableView so the dividing line between cells is invisible [UIColor clearColor], or change the size of the UITableView's height depending on how many cells you have.
If you add a footerView to the UITableView then it will not extend all the way to the bottom.
I solve this problem on the story board.
Create one more cell. if you want 3cells, then make 4cells.
Make whatever you want on cell. put the UIButton or UILabel any way. But except 4th cell.
Expend your 4th cell's height, to the bottom.
And finally, check hidden in attributes inspector. It makes 4th cell hidden.
That's it!
And I add one image file. I hope it help your work. Thanks.
Simple solution is to set footer's frame to nil:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*........*/
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
return cell;
}
I would use a regular View Controller and insert a TableView of the required table height.
Then if you really want to you can do stuff with the cell height and label sizes.
I have a question about the usage of UITableView. I have added a UIView above the cells of my UITableView (see image).
This is very nice because I can add some images and labels there and it will scroll with the cells of the table view. Now I am calling some REST API to get an image which I want to add in this view above the cells. The problem now is that I dont know the height of the image, so I have to calculate it based on the aspect ratio which already works fine. When I add the image I can change its height correctly and move down labels and buttons BUT the image overlaps some of the visible cells.
My question: How can I move down the frame of the container? of the cells? dynamically based on my image respective View height?
I have tried to set the height of the View in the TableView but it has no effect. So I suppose that I have to set the y start position of the cells but I dont know how.
Do I need to set an y offset in the delegate method -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ?
Any ideas?
I think the key to this is setting your view to be the table view's tableHeaderView after you change the size of the view. I did it like this in a test app,
-(void)layoutHeader {
self.label.text = #"This is a long text to see if it expands to take up multple lines. The quick red fox jumped over the lazy brown dog.";
[self.label setPreferredMaxLayoutWidth:self.tableView.frame.size.width];
CGRect stringRect = [self.label.text boundingRectWithSize:CGSizeMake(self.tableView.bounds.size.width - 40,CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:#{NSFontAttributeName:self.label.font} context:nil];
CGRect headerFrame = self.header.frame;
headerFrame.size.height = stringRect.size.height + 40;
self.header.frame = headerFrame;
[self.tableView beginUpdates];
self.tableView.tableHeaderView = self.header;
[self.tableView endUpdates];
}
I called this with a delay from viewDidLoad as a test. The beginUpdates, endUpdates code isn't necessary if you don't want to see the rows move down to accommodate the new view size. The property, header, is an IBOutlet to the view I added to the top of the table view in IB, and "label" is a subview of that view.
I would personally just use tableView:viewForHeaderInSection: to build the view out, and in tableView:heightForHeaderInSection: calculate the new height and return that. That way you don't have to worry about bumping things down within the tableView since UITableView will handle the rest for you once you. Just make sure to call [_tableView reloadData]; on your tableView after you get the image.
I have a UITableViewController that is in a storyboard. I want to add a header to it so I followed the instructions in the following post. I dragged a UIView up on top, and on top of that i dragged a couple of images.
Table Header Views in StoryBoards
Now that seemed to work fine, but the header scrolls along with the entries in table cells when i scroll up. Also, they seem to scroll underneath the time and battery indicator...not sure why that is.
So in the comments of that post i saw that you need to implement the following function to return the UiView to get it to "stick". The only way I saw how to get the UiView from the storyboard was to set the tag and then look it up, also shown below.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section.
{
int tagNumber = 2;
UIView *headerView = (UIView *)[self.view viewWithTag:tagNumber];
return headerView;
}
The issue with all of this is the header still scrolls. How can i get the header view to just stay on top?
Thanks!
I'm creating a mail screen using which visually resembles the iOS native email app. It looks like this (Both images are of the same screen. First one is the top half and the second one is the rest of it).
The difference is my mail screen has more custom fields in addition to normal To, Cc, Subjet fields.
I'm using a UITableViewController to create this. Below is a code snippet which creates a cell (For each cell it's pretty much the same).
- (UITableViewCell *)tokenTableView:(TITokenTableViewController *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
self.tableView.frame = CGRectMake(0,0,320,320);
UIView *contentSubview = nil;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierSubject];
if(!self.txtSubject) {
self.txtSubject = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.txtSubject.frame = CGRectMake(10, cell.frame.size.height / 2 - self.txtSubject.font.lineHeight / 2, tableView.tableView.bounds.size.width, 30);
self.txtSubject.placeholder = #"Subject";
[self setupMailData:indexPath.row];
}
contentSubview = self.txtSubject;
}
Say, I open up a draft. All the details in the input fields are filled and without changing anything, I hit send and it crashes the app. I know what's causing this. The problem is that normally the cells that are under the viewable portion of the screen gets created as you scroll down, right? But in this scenario, if I send it without scrolling down but those cells below the viewport don't exist thus it throws the error.
If I open the draft, scroll down and hit send, it works fine.
I need to know if there's a way to create all these cells at once. Even the cells that are below the viewport at first. Not depending on the user to scroll down.
I hope you have an idea about my situation. Can anyone suggest a solution?
Thank you.
follow steps:
Take uiscrollview and set scrollview frame as which you want to display.
Take uitableview as a subview of uiscrollview
set property Scrolling Enabled = NO (uncheck checkbox in .xib) of uitableview
call reloaddata method of uitableview
set tableview frame and contentsize of scrollview
tblEmail.frame = CGRectMake(yourXPos, yourYPos, yourWidth, tblEmail.contentSize.height);
scrollObj.contentSize = CGSizeMake(yourScrollWidth,tblEmail.contentSize.height+10);
so, the height of tableview is equal its contentsize. so, its create all cells at a time. and set contentsize of scrollview is equal tableview contentsize. so, the scrolling feature is worked like uitableview scrolling...
Use a Storyboard, add a UITableViewController and set the 'Content' to StaticCells.
Then you can define all the cells and their content in the Storyboard. You can even wire stuff up to IBOutlets in your UITableViewController subclass and they will all be there for you when viewDidLoad is fired ...
When using a Storyboard your code for getting the ViewController looks like:
[[UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil] instantiateInitialViewController];