Can't remove lines behind SearchResultsTableView cells - objective-c

I'm creating an iphone application using Objective-C/Xcode. I have a setup where when I click the search box, the search display view shows up and as I type into the searchbox, the searchDisplayController loads the searchResultsTableView cells with rows consisting of autocomplete terms.
because the results cells are a lot bigger than the autocomplete cells, I have the following to manage row height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return 30;
} else {
return 90;
}
}
However I get some weird behavior where the separator lines behind the cells are showing and making an ugly appearance.
(To clarify which separator lines are coming from where, I used
self.searchDisplayController.searchResultsTableView.separatorColor = [UIColor redColor];
)
Do you know how I could remove/hide these background separator lines from being shown in this view? I've tried various color/transparency and cell size manipulations and searched google/SO but could not figure it out.

Try changing your tableView to style to Grouped

Related

Set margin between UITableViewCell using Objective C

Is there a best way to set margin between UITableViewCell, i have one image and a label in table cell, i know this question can be marked as possible duplicate but i have searched a lot and the solution found almost everywhere was ;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return yourArry.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
but problem is that when i tried the above code, the function cellForRowAtIndexPath returned 0 every time and ultimately the whole table was showing the same value in each cell. As i am new to IOS developing, i am unable to resolve this issue, any suggestion will be highly appreciated.
Resolve it, i just set the margin bottom (reset the constraints in AutoLayout) between the imageView and cell container like 10.5, now the imageView is not getting attached with the next cell.

how to create uitableview with different custom cells?

I've got a UIImageView to place a picture there and UITableView to place comments there. The part of the view with UIImageView should be scrolled with comment cells, that's why separate UIImageView and UITableView can't be used - the image won't be scrolled. If UIScrollView is used, than I receive scroll in scroll. Can cellForRowAtIndexPath method be used to create different cells? E.g.:
if (indexPath.row == 0) {
CellWithImage * cell = (CellWithImage *)[tableView dequeueReusableCellWithIdentifier:#"CellWithImage"];
//some code here
return cell;
}
else {
CellWithComment * cell = (CellWithComment *)[tableView dequeueReusableCellWithIdentifier:#"CellWithComment"];
//some code here
return cell;
}
For your case, its better to make the imageview part of the header view for the section
Yes, you can use different identifiers to load different cell types and use them together inside the same table. In fact, your case is somewhat simple -- you're only using a different cell for the first row. You could easily choose the cell type based on the type of data that will be displayed in the row, position of data within a hierarchy, etc.

Make cells appear and disappear in TableView

I making an app with a table view and a data source (core data). In this table i group several tasks ordered by date, and i have this segmented control.
I want the table to only load the tasks later or equal than today's date, when the user taps the second segment i want to show all tasks, if he taps the first segment the table must only show the later dates tasks again.
The problem is:
1 - I'm using fetchedResultsController associate with a indexPath to get the managed object.
2 - I use the insertRowsAtIndexPaths:withRowAnimation: and deleteRowsAtIndexPaths:withRowAnimation: methods to make the cells appear and disappear. And this mess with my indexPaths, if i want to go to the detail view of an specific row it is associate with a different indexPath, after delete the rows.
This problem was fixed by a method i did, but i still have other problems of indexPaths and cells, and it seems to me that is gone be me messy to each problem a fix.
There is a simple way to do that?
I tried just to hide the cells instead of delete, it works just fine, but in the place of the hidden cells was a blank space, if there is a way to hide these cells and make the non-hidden cells occupy the blank space i think that will be the simplest way.
Anyone can help me?
set the height of the cell to 0 when it hides, and set the height back to the original value when it appears.
TableViewController.h
#interface TableViewController{
CGFloat cellHeight;
}
TableViewController.m
- (void)cellHeightChange{
//if you need hide the cell then
cellHeight = 0;
cellNeedHide.hidden = YES;
//if you need hide the cell then
cellHeight = 44; // 44 is an example
cellNeedHide.hidden = NO;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
switch (section) {
// for example section 0 , row 0 is the cell you wanna hide.
case 0:
switch (row) {
case 0:
return cellHeight;
}
}
}
When the user taps on a segment execute a new fetch request on your managed object to give you an appropriate array (either an array of all dates, or the greater/equal dates). Then use reloadData on the tableView using this new array in the datasource.
or
Give the cell's you wish to hide a height of 0?

UITableView don't float section headers

Is it possible to not float the section headers for a UITableView with style UITableViewStylePlain?
I'm building AcaniChat, an open-source version of iPhone's native Messages app, and I want to make the timestamps section headers, but they shouldn't float.
I know that section headers don't float for table views of style UITableViewStyleGrouped, but that style looks less like what I'm going for. Should I just use that style and restyle the table view to make it look how I want?
I might do that if I can figure out how to make https://stackoverflow.com/questions/6564712/nsfetchedresultscontroller-nsdate-section-headers.
The interesting thing about UITableViewStyleGrouped is that the tableView adds the style to the cells and not to the TableView.
The style is added as backgroundView to the cells as a class called UIGroupTableViewCellBackground which handles drawing different background according to the position of the cell in the section.
So a very simple solution will be to use UITableViewStyleGrouped, set the backgroundColor of the table to clearColor, and simply replace the backgroundView of the cell in cellForRow:
cell.backgroundView = [[[UIView alloc] initWithFrame:cell.bounds] autorelease];
I guess either you will have to use two kinds of custom tableCells or skip the tableview entirely and work on a plain scrollview to achieve this kind of style.
This can now be done in two quick and easy steps (iOS 6 only):
Change your UITableView style to UITableViewStyleGrouped. (You can do this from Storyboard/NIB, or via code.)
Next, set your tableview's background view to a empty view like so [in either a method such as viewDidAppear or even in the cellForRow method (though I would prefer the former)].
yourTableView.backgroundView = [[UIView alloc] initWithFrame:listTableView.bounds];
Voila, now you have your table view - but without the floating section headers. Your section headers now scroll along with the cells and your messy UI problems are solved!
This works because UITableViewStyleGrouped seems to now work by adding a background view to a plain UITableView, but without the floating section headers.
[N.B. Earlier to iOS 6, individual background images were added to UITableViewCell's.]
Do try this out and let me know how it goes.
Happy coding :)
EDIT: for iOS 7, simply change the table view style to 'UITableViewStyleGrouped' and change the view's tint color to 'clear color'.
You can achieve this by putting the headers into their own sections. First double your number of sections. Then for the even-numbered sections, return your header as the header and zero as the number of rows. For the odd-numbered sections, return nil for the header.
Assuming you're using an NSFetchedResultsController, it would look something like this:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.fetchedResultsController.sections.count * 2;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if ((section % 2) == 0)
{
section /= 2;
id<NSFetchedResultsSectionInfo> sectionInfo = self.fetchedResults.sections[section];
return sectionInfo.name;
}
else
{
return nil;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ((section % 2) == 0)
{
return 0;
}
else
{
section /= 2;
id<NSFetchedResultsSectionInfo> sectionInfo = self.fetchedResults.sections[section];
return sectionInfo.numberOfObjects;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((indexPath.section % 2) == 0)
{
return nil;
}
else
{
indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section/2];
id object = [self.fetchedResultsController objectAtIndexPath:indexPath];
// configure your cell here.
}
}

UITableView row height not drawing taller with text

I'm trying to mimic the address cell in Address Book / Contacts App.
I want a cell with style UITableViewCellStyleValue2 to display an address such as:
// 123 Fake St.
// Suite 555
// Denver CO, 80000
But actual cell isn't drawing the way I want. The label is drawing outside the bounds of the tableview row and part of top of the label is being cut off by the row directly above it.
Here's what I have so far:
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.autoresizingMask = UIViewAutoresizingFlexibleHeight; //doesn't seem to do anything
self.tableView.rowHeight = 88.0f; // default is 44.0
cell.detailTextLabel.numberOfLines = 0; //unlimited lines
An NSLog statement confirmed the rowHeight is set to 88.0.
I realize a delegate method exists to change the row height. However, in my current app I only need this one cell to expand with the text, so I didn't feel it necessary to implement the delegate method.
Thank you for your help.
I don't think that setting row height this way (self.tableView.rowHeight = 88.0f;) for a single row will work. You should implement the delegate method which in your case is very simple, i.e.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ([indexPath row] == MY_TALLER_CELL_ROW) ? 88.0f : 44.0f;
}
I think you'll probably have more luck not using the cell's default textLabel and detailTextLabel views; instead, create your own labels and add them to the cell's content view.