UITableView custom separator, hidding when selecting - xcode

I've got quick question. I've got a UITableViewController with custom cells which have custom separator (as a UIImageView that is a subview of cell.contentView). Now when I'm selecting a cell I want to hide my separator so it would not be visible on my highlighted background.
I was trying to use such constructions as:
self.separatorImageViewTop.frame = CGRectMake(-240, 0, 120, 2);
self.separatorImageViewTop.hidden = YES;
self.separatorImageViewTop.alpha = 0;
[self.separatorImageViewTop.frame removeFromSuperview]
Each of this ways is working but each of them is making a blinking effect on custom separator when cell is selected. How can I avoid this blinking effect?
My code is invoked from:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
but I've tried to use with:
-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
hoping that actuall highlighting of a cell would occur after tableView:willSelectRowAtIndexPath: method, but the result are the same - still blinking effect of a disapearingUIImageView`.
Any ideas?

Try override this method in your custom cell:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}

Related

Header view is not display after search iOS8 + XCode6

I have working application for iOS7 and below
I used UISearchDisplayController for search in table.
Problem :
After search header view is not display in iOS8.
as display in below images.
Before search :
After search :
I tried using UISearchController but also have same problem
i used this code link
I add below code in TPSMastreViewController.m
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *v = [[UIView alloc] init];
v.backgroundColor = [UIColor greenColor];
return v;
}
I checked that delegate - (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
is not called in the case of iOS8.
Edit :
What i understand is only UITableViewDataSource delegate is called, UITableViewDelegate did not.Please not that i set both delegate in ViewDidLoad
Question :
1] Is it an UI change ?
2] Any one have patch so that delegate method will call forcefully.
I found answer so writing here it may help others facing same problem
just need to add delegate heightForHeaderInSection and it will show header view for both searchResultsController for UISearchController(iOS8) and searchResultsTableView for UISearchDisplayController(iOS7)
Add below code in TPSMastreViewController.m and it will solve problem.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20;
}
I found my answer by reading this question :)
in iOS 8 UITableView heightForHeaderInSection is not optional

UITableView custom cell not displaying data

Here is the story. I have a simple app in which I use 2 tabs, both of them with UITableView. The first tab/view is called "Favorites" and the second one is called "My Profile." In addition I have a custom UITable cell named "CustomViewCell.xib" with an identifier of the same name. FavoritesViewController is a subclass of UITableViewController and that one is running perfectly. But for the ProfileViewController I am using normal ViewController because I don't want the whole view to be UitableView. To make that possible, I the following to ProfileViewController.h:
#interface ProfileViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, strong) IBOutlet UITableView *tableView;
then in the viewDidLoad of ProfleViewController.m file I have:
[self.tableView registerNib:[UINib nibWithNibName:#"CustomViewCell" bundle:nil]
forCellReuseIdentifier:#"CustomViewCell"];
The following methods are implemented just as in the other tab that's working:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here I am customizing the cell and returning it.
}
When i run the app, the cells are the right height, but are empty.
To debug I put a break point right before cellForRowAtIndexPath, and the app runs without an error which it shouldn't. So, the program is not even getting to this method. So, I think that's the reason the cells are empty. Do you guys have any idea what might be causing it to skip this particular method? can you also explain it in simpler terms because I'm newbie, you know?
In you ViewDidLoad method, add this code:
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
Then check again if the breakpoint works
Have you implemented a UITableViewDataSource? A UITableViewController is the delegate and datasource for the Table View it manages so you can define all those methods in the View Controller itself.
For a UITableView that is a subview of a UIViewController, you need to define the Table View's delegate and datasource.
See here: http://www.aboveground.com/tutorials/adding-a-uitableview-to-a-custom-uiview

UITableView Edit Mode Textfield

I have triggered an EditMode in UITableView, but I found that all my UILabel and a UITextField on the left are not shown in the correct position. How can I fix this. Thanks!
Use this code
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
you have taken grouped TableView and added subvies on cell.
Need to add custom Objects always on Content View.

Must a custom table view cell be prototype cell instead of static cell?

I have been googling and only seemed to be able to find examples of how to create custom cell as prototype cell.
My question is: Can I create custom table view cell as static cell?
Thanks in advance!
Eve
No, in Storyboard you can edit your cell like you want by dragging objects into your cell.
You just have to make a new class of UITableViewCell and use that one in Storyboard, connect everything up if needed and use the following methods:
#import "YourTableViewCell.h"
- (YourTableViewCell *)tableView:(YourTableViewCell *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
....
[self configureCell:cell atIndexPath:indexPath];
}
- (void)configureCell:(YourTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath

Xcode 4.2 iOS 5 : Multiple segues from a UITableView

I'm starting now with Xcode on 4.2 for iOS5 and there are a few changes and I'm now crossing a problem that I can't figure out a way to solve it.
I'm doing an example with a UITablwView that is populated programmatically with 2 Sections, 1st section with only 1 Row, and 2nd Section with 3 Rows.
My aim is to select a row from the table, and based on that row, the user will be redirected to different Views.
For example:
selecting section 0 row 0, app pushes to view 1 - name setting //
selecting section 1 row 0, app pushes to view 3 - address setting
The old fashion way, this is quite simple, just needed to init a UIViewController with initWithNibName and then push the view.
Now with the storyBoard everything changes, or at least I think it changes because I can't see how to get the same result since I can't set multiple segue's from the tableView to different UIViewControllers...and to do the old fashion way I can't see where I can get the NIB names from the views on the storyBoard to init an UIViewController to push.
Does any one knows how to get to this result??
Define two "generic" segues (identified as "segue1" and "segue2", for example) in the storyboard from your source view controller, one to each destination view controller. These segues won't be associated with any action.
Then, conditionally perform the segues in your UITableViewDelegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Conditionally perform segues, here is an example:
if (indexPath.row == 0)
{
[self performSegueWithIdentifier:#"segue1" sender:self];
}
else
{
[self performSegueWithIdentifier:#"segue2" sender:self];
}
}
I have the same problem as you do. The problem is that you can't link your tableViewCell to multiple view controllers. However you can link your source view itself to multiple view controllers.
Control-drag the master view controller (instead of table view cell) from the scene viewer to whatever view controller you want to link. You can do this as much as you want. Notice that the segue shown in source view controller scene should be something like "Push Segue from Root View Controller ..." instead of "Push Segue from NavCell to ...".
Identify each segue link a unique name like "toDetailView1"
Finally, custom the selection in your source view controllers:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % 2 == 1) {
[self performSegueWithIdentifier:#"toDetailView1" sender:self];
} else {
[self performSegueWithIdentifier:#"toDetailView2" sender:self];
}
}
Like #陳仁乾 and #Marco explained was completely correct. To make everything a little bit easier I would recommend you to use a single NSArray which will be initialized when viewDidLoad. Just name the segues the same as your UIViewControllers, this way you can Display a correct description of what UIViewControllers you can choose from and you can also perform the segues from this NSArray:
(Actually I'm not sure if it can cause any problems calling the segue the same as the UIViewController you want to call. Please let me know if this is BadPractise)
viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
_arraySessions = [[NSArray alloc] initWithObjects:
#"MyViewControllerName", nil];
}
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:#"overviewCell"
forIndexPath:indexPath];
[cell.textLabel setText:_arraySessions[indexPath.row]];
return cell;
}
didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:_arraySessions[indexPath.row]
sender:self];
}

Resources