UItableview cell not expanding to show text - objective-c

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.

Related

NSTableview cell row overlapping issue

I have NSTableView in Xib and connected outlet for that.I am loading the cell data using Key value bindings with NSArrayController.I need to fill the cell rows dynamically.I did it.But I am facing the problem,my Tableview cells are getting merged and lines of cell row are not visible.
Why is this happening,How to solve this.Can anybody have ideas please.
It is happening in 10.7.
It is probably due to cells heights in your table are higher that used in TableView by default. If this is your case:
Evaluate cell height in IB (row height in Size Inspector)
Add delegate method in proper view controller:
(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0; // for example!
}

TableView with dynamically height

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;
}

SplitViewController for iPad behaviors

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;
}

Getting name of cell from indexPath / Swip Gesture

The Situation
I'd like to be able to get information about the title of a cell within a UITableView when the user swipes the cell (to display the "delete" button).
The Code
When the user swipes a cell in the UITableView, this method is fired:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
The Problem
I need to be able to get the name of the cell the user "swiped" so that my iOS (Obj-C) app can do various operations, etc.
Everything Else
I know that the indexPath has something, but I can't get an NSString from it (which is what I need).
I was also thinking that a workaround such as using a gesture recognizer instead of the above method might be able to provide me with more information about the cell.
Any ideas as to how I can get the name of the cell when the user "swipes to edit / delete"?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *text = cell.textLabel.text;
// do something with text
}
Please, how does your table work in the first place - you don't seem to understand the basic principles of it. You back your table up with a data model. YOU provide and construct the cells for each indexPath, so you should know how to access the data in your model using that swiped indexPath, no?
Of course you could also ask the tableView delegate (yourself) for the swiped cell by calling tableView:cellForRowAtIndexPath: and then check the labels on that cell.
Have a look at the implementation of your tabkeView:cellForRowAtIndexPath: method all your info of how to get the data should be there...
All in all it's pretty easy, if you provide some code you sure will get more hints.

Search result of UISearchDisplayController has other cell layout and behaviour than searched table

I am using storyboarding. I have an UITableView with one prototype cell. This cell is of style "subtitle". I have added a segue from the cell to the detailed view. So when the user taps a cell it will open the corresponding editor... That all works great.
Now I added a UISearchDisplayController an a UISearchBar, implemented the delegates. That works very well.
But in the search result table the cells are of style "default" and are not tapable. What do I have to do to get a result table looking and behaving like the "unsearched" table?
I would like to contribute for answer #1 this is what I did and it worked for me
in the method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
instead of assigning the cell from the parameter tableView
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
assign it directly from the TableView on the view so you have to replace this
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
with this
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Found the problem...
The method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
pulled the cell from the tableView, which is in the result case not the tableView from the storyboard but the resultTableView from the SearchDisplayController.
I now get the cell to display in both cases from the table view in the storyboard and now it works.
I've been using ios 7.0 and Xcode 5.0. I found that search display controller is using the same tableview layout as the delegate view controller. All you have to do is judge if the current tableview is the delegate view controller's tableview, or the search display controller's tableview. But remember to add the sentence
tableView.rowHeight = self.tableView.rowHeight;
in the following code snippet:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView)
{
tableView.rowHeight = self.tableView.rowHeight;//very important!
return [self.searchResults count];
}
else
{
...
return ...;
}
}
if you forget to implement that sentence, then the row of the table view of search display is only as high as a default row, which makes you think it doesn't look like the "unsearched" table.
There is a possible answer to this here. It may not work entirely for you, but as I explained, the UISearchDisplayController creates the table view.
Check the documentation and you can get a better understanding of it, but it states:
You initialize a search display controller with a search bar and a
view controller responsible for managing the original content to be
searched. When the user starts a search, the search display controller
is responsible for superimposing the search interface over the
original view controller’s view and showing the search results. The
results are displayed in a table view that’s created by the search
display controller. In addition to the original view controller, there
are logically four other roles. These are typically all played by the
same object, often the original view controller itself.
In my case UISearchDisplayController was using right cell type (custom) but height of cell was wrong so I had to use
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method to fix it.