I'm programming on objective-c. I have a viewController with tableView. I would like that my tableView has a dynamically height like on a picture below (Tweetbot). How can I make it?
Yes. However its not clear that this table is "short" - it may be that it has a transparent background and only two cells. In any case, to make a short table you would create a UIViewController class with a normal view (ie a UIView). Create a UIImageView and add the image to it (assuming you want a big image), and add that to the view (you could do this in IB). Then create a UITableView of the desired height, and add that too to the UIIView's subviews. Now you have a container view (self.view) with two subviews, the table being the last (so its on top).
Most likly tweetbot doesn't add a UITableView upon a UIViewController. They most likely use the UITableViewController from scratch, giving it a background and (in this case) showing only two cells with a custom height. That is also the "way-2-go" when using the Table View.
You should use -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath method and use if condition or switch case in this method.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==2) {
return 89;//write your image view's height here.
}
return 44;
}
Related
When I use a custom view as the cell of a view-based NSTableView, the custom view is somewhat below the table row. When I click on it, instead of affecting the elements (e.g. text field) custom view, the table row was selected (and highlighted). I have to reclick to select the text field.
- (NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSLog(#"We are creating views!");
NSTableCellView *newView;
newView = [tableView makeViewWithIdentifier:#"PostCell" owner:self];
NSTextField *newTextField = [[NSTextField alloc] init];
[newView addSubview:newTextField];
return newView;
}
When I disable the row selection according to NSTableView - Disable Row Selection, there was no selection.
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)tableView {
return NO;
}
But I still cannot select directly the text field. What's worse, I cannot even select it using the mouse. Only tab on the keyboard works.
There seem to be something above it. But is it the "table column" shown in interface builder? Or something else?
How can I fix this?
Use a custom subclass of NSTableView and override -validateProposedFirstResponder:forEvent: to return YES.
See this blog entry from the Apple engineer who wrote the view-based table view code.
Make sure following code is present.
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex {
return YES;
}
You may try logging the subviews Or you can check superviews of view.
This will help to understand view hierarchy.
Also on side note if one of the view's userInteraction is disable then it's subview's won't be able to receive the events. Please verify that all the views and it's subviews userInteraction is enable.
I hope this helps.
I have a uitableview cell. I want it to expand and show a lot of text. I set it up with autolayout and constraints. It looks right, but when I run it only shows up to two lines. I don't understand. Can someone point me in the right direction? Thank you.
Here's a link to an image of the setup: https://docs.google.com/document/d/1V8jetMrVDK4ebaconz9PL0y3DnJUqXmPkfyhK-0Nhbc/edit?usp=sharing
From the 2014 WWDC, with iOS 8, if you
Set up autolayout constraints relative to cell.contentView
Use the estimatedRowHeight property
Dont implement -[UITableView tableView:heightForRowAtIndexPath:]
Dont use the rowHeight property
then you can take advantage of self-sizing cells that will expand automatically based on their content.
Check out WWDC '14 under "What's New in Table and Collection Views." You'll only need to watch the first 25 minutes or so.
Implement the following two TableView methods
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Working with Self-Sizing Table View Cells Here is a useful reference.
I'm creating a custom UITableViewCell from an xib. However, the cells don't automatically fit the same height I set in the xib file. Is there a way to get the height of the xib in the heightForRowAtIndexPath so that I can accurately set the height without having to hard code it?
Selecting the UITableView on the storyboard, or view etc, within the interface builder you can set the cell height to match your custom cell nib's height.
Go to the Utilities panel and select the tab as highlighted in blue in the picture below. Set the row height here.
I hope this helps with what you are looking for.
Cheers
You can also use this delegate method of table View
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Height same as your XIB of cell
}
How can I create a ViewController which has a fixed MapKit above a scrolling TableView?
I am coding this using Storyboards, and while I am an experienced developer this is my first time using iOS, XCode and Objective-C. I currently have a method which kind of works, but the method which I am currently using works by setting the MapKit as the section header of the table view inside a UITableViewController and does not look right. (It works since as I have only one section that MapKit section will always be fixed while I scroll the table view.)
The code that does this looks like this:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 200.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 200)];
return mapView;
}
Unfortunately doing this means that the scrolling bar appears alongside the Map as well as the table view. Instead, I wish the scrolling bars to only be as tall as the table view.
There are other answers around the site about doing stuff like this, but none of them mention the height of the scroll bars (and the elegance of the code.)
Any ideas?
The link you provided is exactly what you should do, but in the Xib file also include the MKMapView above the table view, and set the outlets properly for that as well(And implementing the proper delegate protocols). The scroll bar will only go as high as the table view because it's a subview of the actual table, and, generally, this is the accepted way of doing things on the UI unless you want to do absolutely everything programmatically.
In this case you can take a separate UIView and place it after Exit. Put your mapView inside that UIView and do the required. Also draw an outlet for your tableView(myTableView) as well as the UIView(viewWithMapView). Now add this in your viewDidLoad() :-
[_myTableView setTableHeaderView:_viewWithMapView];
This will add your mapView as tableView header instead of section view header.
I am working with the UISplitViewController in iPad application.
Currently, I found two issues:
1. I can't modify the width of the master view
2. I try to use the customized cell in the master view, but it seems not possible to adjust the width and height of the cell.
Do you have any ideas on the two issues regarding to the standard UISplitViewController?
Thanks,
Mike
1) You cannot change the size of detail view.
Please check the following link, From that link you will get alot of information:
Change the width of Master in UISplitViewController
2) Use the heightForRowAtIndex delegate method. return 60 from that method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}