NSTableview cell row overlapping issue - objective-c

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

Related

UItableview cell not expanding to show text

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.

How to tell if a UITableView's cell is visible on the screen

I'm writing an Objective-C app for iOS 8. I was wondering if anyone knows how to tell if a UITableViewCell in a UITableView is on-screen.
For example, if the y value of the UITableView's contentOffset is 0 (meaning that the UITableView is scrolled to the top) and I programmatically select row 2, I don't want to scroll at all because row 2 is already visible (assuming that the UITableView is large enough to show at least 3 rows). However, if I programmatically select row 10 (which is off screen), I want to programmatically scroll to that row.
This is the code I use to scroll to the selected row:
[self.tableView scrollToRowAtIndexPath:[_tableView indexPathForSelectedRow]
atScrollPosition:UITableViewScrollPositionMiddle
animated:NO];
Now, I just need to nest that code inside an if-statement that checks to see if the cell at the currently-selected row is fully visible on-screen.
Any suggestions?
Since you want the selected row to be visible with the least amount of movement, use the method made just for that:
[self.tableView scrollToNearestSelectedRowAtScrollPosition: UITableViewScrollPositionNone animated:YES];
From the docs for UITableViewScrollPositionNone:
The table view scrolls the row of interest to be fully visible with a minimum of movement. If the row is already fully visible, no scrolling occurs. For example, if the row is above the visible area, the behavior is identical to that specified by UITableViewScrollPositionTop. This is the default.
Try this,
NSIndexPath *path = [tableView indexPathForCell:tableView.visibleCells.firstObject];
[self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
There is no way to ask to the tableview if a view is shown at specific time.
What you can do is to be delegate for this tableview and implement this methods:
- (void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView
didEndDisplayingCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
You can implementing this methods track the uitableview showing at that moment.

Getting Height From a XIB

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
}

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

Change UITableView row height without dismissing keyboard

I have a TextView inside a UITableViewCell. The text inside the TextView can be edited right there in place.
The TextView grows and shrinks vertically depending on the number of lines the text contains. So far I haven't found a possibility to also let the row containing the TextView grow and shrink dynamically.
[tableView reloadData];
or
[tableView reloadRowsAtIndexPaths: withRowAnimation:];
don't work, because they dismiss the keyboard on every change.
Is there a way to change height of an individual row in a UITableView without dismissing keyboard?
Yes, you can have the row heights adjust as you type. It's not documented, and it defies reason, but all you need to do is set the new value in tableView.rowHeight (or have heightForRowAtIndexPath:ready to compute the new heights), then do this:
[tableView beginUpdates]; // updates the row heights ...
[tableView endUpdates]; // ... nothing needed in between
The task is to invoke row height recomputation without cell reuse (to save current responder).
One can call moveRowAtIndexPath:toIndexPath: for the same indexPath right after height change
- (void)textInputTableView:(UITableView *)tableView cellHeightDidChangeForIndexPath:(NSIndexPath *)indexPath
{
[tableView moveRowAtIndexPath:indexPath toIndexPath:indexPath];
}
After reloadRowsAtIndexPaths the cell changes memory value, so if you call becomeFirstResponder just after the reloadRowsAtIndexPaths, you are trying to set as firstResponder the old cell, which does not exist (becomeFirstResponder returns false and keyboard exits).
The solution is to call again cellForRowAtIndexPath in order to get the new memory value of the reloaded cell, and then call becomeFirstResponder to that cell.