i have a dynamic tableviewcontroller SideBarTableViewController.m/.h .
Have a pop up view controller - popUpViewController.m/.h
Have subclassed a cell of SideBarTableViewController -> RegisterTableViewCell.m/.h and added a button outlet from the cell to it.
Have connected the cell to popUpViewController in storyboard using "present As popover" segue and the segue is given identifier "popover". The anchor point in storyboard has been set to Tableview for now , changing it later in preparesegue .
RegisterTableViewCell.h
#property (weak, nonatomic) IBOutlet UIButton *PopoverAnchorButton;
SideBarTableViewController.m
#import "RegisterTableViewCell.h"
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"popover"] && segue.destinationViewController.popoverPresentationController){
UIPopoverPresentationController *popController = segue.destinationViewController.popoverPresentationController;
popController.sourceView = sender;
RegisterTableViewCell *cell = [[RegisterTableViewCell alloc]init];
segue.destinationViewController.popoverPresentationController.sourceRect = CGRectMake(cell.PopoverAnchorButton.frame.size.width/2, cell.PopoverAnchorButton.frame.size.height, 0, 0);
popController.delegate = self;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
RegisterTableViewCell *regcell = [[RegisterTableViewCell alloc]init];
[regcell.PopoverAnchorButton addTarget:self action:#selector(PresentPopover:) forControlEvents:UIControlEventTouchUpInside];
// Configure the cell...
return cell;
}
-(void) PresentPopover:(UIButton *)sender
{
NSLog(#"present popover called ");
[self performSegueWithIdentifier:#"popover" sender:sender];
}
popUpViewController.m
- (IBAction)closeview:(id)sender {
[self.view removeFromSuperview];
}
Problem:
The popup is displayed from the left end of the cell, but wat i see , there is a delay in popup presentation . Normally , first click in the cell, popup comes up as expected ,
second click -> little delay ,
third -> little more delay ... (delay not always increasing though, but fixed 6-7 seconds )
let the ipad be idle for say 6 seconds , and again click in the cell, popup shows immediately .
double clicking(2 taps ) in the cell displays it immediately but with a warning :
2016-07-11 22:53:05.462 Player-app_03[1947:590814] Warning: Attempt to present <UINavigationController: 0x125026400> on <SideBarTableViewController: 0x124d258f0> which is already presenting (null)
What is happening here ? i am clueless. Anybody please help.
The problem is likely to be found in the actions of the segue.destinationViewController, which, from the OP code, appears itself to handle another view controller. To get a handle on this, omit the prepareForSegue logic that you have, and omit anything in the destination vc's viewDidLoad or viewWillAppear that is related to vc presentation.
The segue.destinationViewController is the view controller that's going to get presented. Anything that messes with that is asking for trouble.
The increasing lag time is very likely caused by the action (inaction, rather) in closeview, which is merely removing the popup view controller's view, leaving the view controller itself around indefinitely. The proper action in that method is to call:
[self dismissViewControllerAnimated:YES completion:nil];
Also, please note that any place you directly allocate a table view cell (done twice in the OP code), is indicative of at least a misunderstanding, and probably a mistake.
My UI structure is as follow:
UITabBarController (TBC) -> UINavigationController (NC) -> UITableViewController (TVC)
(for the simplicity of the example lets say the TBC has only one controller on its viewControllers array - the NC)
My TVC has UISearchBar as its table header, and when the TVC appear I hide the search bar beneath the NC navigation bar by settings the table view content offset.
When user tap a cell in the TVC another view controller is pushed (VC) and hides the tab bar with VC.hidesBottomBarWhenPushed = YES;
Now there is a very annoying behavior that I dont know how to solve:
When the user tap the back button from VC back to TVC, the search bar jumps to be visible even if it was hidden (beneath the navigation bar) before the VC was pushed.
This effect happens only if the TVC doesn't have enough rows to fill the screen, its like the search bar force itself to be visible if there is a place on screen. but its really looks bad and buggy.
I uploaded a simple project that demonstrates the problem, it has the same structure as I described in my question.
I added two bar buttons for your convenience, the "hide bar" button hides the search bar for you, and the "toggle count" button toggle the table view rows count to demonstrate that the issue happens only if there are few items.
Okay.. It looks to me like you've stumbled upon a bug. It should be reported through apples bugreporter (here).
I've made a fairy simple working work-around, but keep in mind that it is a work-around. This will work, but you might have to review it if you have/add other controls to the tableView. It should be safe to use(not acting randomly), and it's not the ugliest of work-arounds, so I think it's fine to use in a release. I've uploaded the same project with the fix here, and you can just go ahead and download it, and you'll probably understand what I've done. I'll explain (in extreme detail) what I've actually thought and done here, in case the download links dies in the future:
Train of thought:
As simalone also said, the problem is that when hidesBottomBarWhenPushed is set to YES, then it will call an additional viewDidLayoutSubviews which somehow resets your current state. We need to override viewDidLayoutSubviews, and check if we are laying out subviews because we are coming from ViewController, or if it's just a regular call. When we establish that the call is indeed because we are returning from ViewController, we need to hide the search bar (only if it was hidden before).
When we return from ViewController, three calls are made to viewDidLayoutSubviews in TableViewController. I'm guessing the first is for tableView, and it seems that the second call is 'for'(or rather from) the tabBar. This second one is the one moving the searchBar down. I have no idea what the third call is, but we can ignore it.
So now there are three things we need to check inside viewDidLayoutSubviews: We need to check if we are returning from ViewController, we need to check if the searchBar was hidden before we pushed(if it should hidden be now), and we need to check that it's the second call to this method.
First things first.
In TableViewController, I added a property #property BOOL backPush; to the header(.h)-file. Now I need to change this variable from ViewController.
In ViewController, I put this:
#import "TableViewController"
...
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if(self.isMovingFromParentViewController)
{
if([self.navigationController.topViewController isKindOfClass:[TableViewController class]])
[((TableViewController*)self.navigationController.topViewController) setBackPush:YES];
}
}
In the code above, when the view is disappearing (I.E pushing forward, back, closing, whatever), I'm checking if we are disappearing because it was removed from the parent. If it is(which it is when the back-button is called), I check if the now-current top view controller is of class TableViewController, which it also is if we go back. Then I set the property backPush to YES. That's the only thing we need in ViewController.
Now, to the TableViewController. I added a counter next to your row-count:
#interface TableViewController () {
NSInteger _rows;
int count;
}
This is to keep track of how many calls have been made to viewDidLayoutSubviews later. I set count = 0; in viewDidLoad.
Now to the magic:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if((self.backPush && count == 0 && self.tableView.contentOffset.y ==
self.tableView.tableHeaderView.frame.size.height) ||
(self.backPush && count == 1 &&
self.tableView.contentOffset.y == 0))
{
if(count == 0)
count++;
else
{
count = 0;
self.backPush = NO;
[self hideSearchBar];
}
}
else if((count == 0 || count == 1) || self.tableView.tableHeaderView.isFirstResponder)
{
count = 0;
self.backPush = NO;
}
}
The first if-statement wants either of these situations:
backPush is YES, count is 0, and searchBar is already hidden.
backPush is YES, count is 1, and searchBar is visible.
If 1. is true, then we increment count by 1.
If 2. is true, then 1. has already happened, and we now know that we are in the second round of viewDidLayout.. when we are coming back from VC AND that the searchBar WAS hidden (because 1. happened) but now isn't hidden. It probably happens in the super-method or something.
Now we can finally push the searchBar out again. I also reset count and set backPush back to NO.
The else if is also pretty important. It checks if count is 0 or 1, or if the searchBar has the keyboard showing. If count is 0 or 1 when it reaches here, it means that the first if-statement failed, e.g that the searchBar wasn't hidden, or that it was scrolled far up.
(When I think of it, the else-if should check if backPush is YES as well. Now it sets those variables repeatedly)
Let me know if you find a better way!
I think this one is simple solution. Thanks to
Sti
for giving some ideas to solve this bug.
Initialize variable var hideSearchBar = false
and inside viewDidLayoutSubviews add this code for maintain same content offset.
if hideSearchBar == true {
self.tableView.contentOffset = CGPointMake(0, self.tableView.tableHeaderView!.bounds.height - self.tableView.contentInset.top)
}
Finally implement below methods.
override func scrollViewDidScroll(scrollView: UIScrollView) {
if self.tableView.tableHeaderView!.bounds.height - self.tableView.contentInset.top == self.tableView.contentOffset.y && self.tableView.dragging == false {
hideSearchBar = true
}
else if self.tableView.dragging == true {//Reset hiding process after user dragging
hideSearchBar = false
}
}
func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if self.tableView.contentOffset.y + self.tableView.contentInset.top <= self.tableView.tableHeaderView!.bounds.height
{
self.tableView.contentOffset = CGPointMake(0, self.tableView.tableHeaderView!.bounds.height - self.tableView.contentInset.top)
}
}
Try to set for TVC
self.automaticallyAdjustsScrollViewInsets = NO
This is a problem caused by hidesBottomBarWhenPushed = YES , if you uncheck Hide Bottom Bar On Push, the searchBar will not appear when VC back to TVC.
Try this in TableViewController.m:
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self hideSearchBar];
}
I can't explain why but I know that if hidesBottomBarWhenPushed = YES for UITabBarController to push vc, viewDidLayoutSubviews will be called more than once when the view appears again. First time subviews keep the same position, whereas the second time be called, subviews will be adjusted for some reason to relayout with the most original position, which is very weird. Do your custom layout in viewDidLayoutSubviews will prevent this to happen even after viewDidAppear.
My solution is a little stupid.
Add this method to the sample code.
- (void)viewWillLayoutSubviews
{
[self hideSearchBar];
}
It seems the tableView will redraw the scrollView inside it.
Since the tableView reset the contentOffset, I made a custom tableView has property to save the hidden status of search bar.Below is the code.Hope it helps.
//
// TableViewController.m
// SearchBarJump
//
// Created by Eyal Cohen on 3/9/14.
// Copyright (c) 2014 Eyal. All rights reserved.
//
#import "TableViewController.h"
#interface CustomTableView : UITableView
#property (nonatomic, assign, getter = isSearchBarHidden)BOOL searchBarHidden;
#end
#implementation CustomTableView
#synthesize searchBarHidden = _searchBarHidden;
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.isSearchBarHidden) {
[self hideSearchBar:NO];
}
}
- (void)setSearchBarHidden:(BOOL)searchBarHidden
{
_searchBarHidden = searchBarHidden;
if (_searchBarHidden && self.contentOffset.y != self.tableHeaderView.frame.size.height) {
[self hideSearchBar:YES];
}
}
- (void)hideSearchBar:(BOOL)animated {
// hide search bar
[self setContentOffset:CGPointMake(0.0, self.tableHeaderView.frame.size.height) animated:animated];
}
#end
#interface TableViewController () {
NSInteger _rows;
}
#property (nonatomic, weak) IBOutlet CustomTableView *mainTable;
#end
#implementation TableViewController
#synthesize mainTable = _mainTable;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view = _mainTable;
[_mainTable setDelegate:self];
[_mainTable setDataSource:self];
_rows = 3;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mainTable setSearchBarHidden:YES];
}
- (void)hideSearchBar {
// hide search bar
[_mainTable setContentOffset:CGPointMake(0.0, self.tableView.tableHeaderView.frame.size.height) animated:NO];
}
- (IBAction)toggleCount:(UIBarButtonItem *)sender {
if (_rows == 20) {
_rows = 3;
} else {
_rows = 20;
}
[_mainTable reloadData];
}
- (IBAction)hideBar:(UIBarButtonItem *)sender {
[self hideSearchBar];
}
#pragma mark - Table view data source
- (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 _rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = #"cell";
return cell;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[_mainTable setSearchBarHidden:NO];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (_mainTable.contentOffset.y == _mainTable.tableHeaderView.bounds.size.height) {
[_mainTable setSearchBarHidden:YES];
}
}
#end
UITableViewController always modifies its UITableviews content offset in its viewDidAppear to make sure that its all rows are visible. So your hacky methods don't work here.
There are several solution to this problem. The one I selected is shown below
First delete that searchBar from your storyboard.
#interface TableViewController () {
NSInteger _rows;
}
#end
#implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_rows = 4; // +1 for searchBar
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
- (void)hideSearchBar {
// hide search bar
[[self tableView] scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndex:1] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
- (IBAction)toggleCount:(UIBarButtonItem *)sender {
if (_rows == 20) {
_rows = 4;
} else {
_rows = 20;
}
[self.tableView reloadData];
}
- (IBAction)hideBar:(UIBarButtonItem *)sender {
[self hideSearchBar];
}
#pragma mark - Table view data source
- (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 _rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0){
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,44)];
[cell addSubview:searchBar];
return cell;
}
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = #"cell";
return cell;
}
#end
The above solution just ensures that automatic scrolling magic is disabled.
If you want your default searchBar to be hidden override UITableView and call hideSearchBar when tableview is initially loaded for the first time.
I fix the bug just like this:
#interface NTTableView : UITableView
#end
#implementation NTTableView
-(void)setContentOffset:(CGPoint)contentOffset{
if (self.contentOffset.y==-20&&
contentOffset.y==-64) {
NSLog(#"iOS7 bug here, FML");
}else{
[super setContentOffset:contentOffset];
}
}
#end
Fix for my somewhat similar situation with a UISearchBar as the tableHeaderView. Not sure if this falls into the same exact scenario, but it hides the search bar when the view appears. (Being unconcerned with the amount of rows in the table view)
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
Setting edgesForExtendedLayout to [.top, .bottom] instead of just .top on TVC fixed problem for me.
Of course, automaticallyAdjustsScrollViewInsets is set to false
EDIT: seems that it only works if tvc.tabBar is translucent
As a weird hack I can only suggest to add an empty cell to the end of cells with height about 400
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _rows + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(indexPath.row == _rows)
{
//cellEmpty - cell identifier in storyboard
cell = [tableView dequeueReusableCellWithIdentifier:#"cellEmpty" forIndexPath:indexPath];
}
else
{
cell.textLabel.text = #"cell";
}
// Configure the cell...
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == _rows)
{
return 400;
}
else
{
return 44;
}
}
your output file
https://github.com/iDevAndroid/SearchBarJump
simply use this code don't make do complex for that
-(void)viewDidDisappear:(BOOL)animated{
[self.tableView setContentInset:UIEdgeInsetsMake(-0.3, 0, 0, 0)];
[super viewDidAppear:animated];
}
here is one problem if you are set UIEdgeInsetsMake(0, 0, 0, 0) the searchBar jumping as in original mode
Very very strange! It works everywhere but here:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyViewController* cliente = [[MyViewController alloc] initWithModeAndClientId:2 c:cid];
cliente.delegate = self;
UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:cliente];
n.navigationBarHidden = NO;
[[n navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:n animated:YES completion:nil];
}
If I tap by a single click on the row, the MyViewController shows after seconds!
If I click twice, it shows rapidly!
In the Profiler, at single click nothing happens...
I have no didDeselectRowAtIndexPath method.
The solution is to put on the main thread the loading of the second controller
dispatch_async(dispatch_get_main_queue(), ^{
// Code here
});
Its issue of threading, when you tap a row in tableview it start a new thread so the presenting a view may take longer to show up on screen.
The solution is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_main_queue(), ^{
MyViewController* cliente = [[MyViewController alloc] initWithModeAndClientId:2 c:cid];
cliente.delegate = self;
UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:cliente];
n.navigationBarHidden = NO;
[[n navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:n animated:YES completion:nil];
});
}
Are you by any chance putting a tableview inside a scroll view? If so the container scrollview is blocking the touch event to the inner table view. This fixed it for me:
self.myContainerScrollview.panGestureRecognizer.delaysTouchesBegan = true
Credit for the answer should go to the OP here: https://stackoverflow.com/a/31040918/1455770
Had the same problem. And it was hard to find. But it was because of following:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return nil;
}
You should return indexPath
I had the same issue on my tableView(swift 4.2). After debugging and taking lots of time it appeared that table view has a boolean property named allowsMultipleSelection.
If allowsMultipleSelection is set to true the table view selection mechanism will change in a way that by selecting each cell the tableView didSelectRowAtIndexPath: is called for the first time and by selecting the same cell for the second time the tableView didDeselectRowAtIndexPath: is called.
This makes tableView didSelectRowAtIndexPath: function to be called on the third selection for the same cell and so the result is double tap for calling didSelectRowAtIndexPath:.
It means that if the number of times a cell tapped are odd (1, 3, 5, ...) then always tableView didSelectRowAtIndexPath: will be called and if the number of times a cell tapped are even (2, 4, 6, ...) then always tableView didDeselectRowAtIndexPath: will be called.
If you want the tableView didSelectRowAtIndexPath: to be called on each selection for a cell then the tableView multiple selection has to be set false, tableView.allowsMultipleSelection = false.
By doing this, every time the cell is tapped tableView didSelectRowAtIndexPath: will be called on table view and by selecting another cell tableView didDeselectRowAtIndexPath: will be called for the cell was selected before and then the tableView didSelectRowAtIndexPath: will be called for the newly selected cell.
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.allowsMultipleSelection = false
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("This will be called for each cell tap")
}
I am developing universal iOS app and try to achieve popover.
I have tried WYPopoverController and FPPopover but those 2 does the same issue.
I have simple UITableViewController having 10 cells putting a static text on each cell (just for a test).
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UILabel *label = (UILabel *) [cell viewWithTag:1];
[label setText:#"test"];
return cell;
}
and try to show this in popover.
Sample code to apply FPPopover is
- (IBAction)test:(id)sender {
PopOverTableViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PopOverTableViewController"];
FPPopoverController *popOver = [[FPPopoverController alloc] initWithViewController:vc];
[popOver presentPopoverFromView:sender];
}
This shows text in 10 cells at a button tap but once I scroll inside of tableview,
the texts disappear and non of tableview data source methods are called afterwards.
It happened for both WYPopoverController and FPPopover so I am assuming there is something wrong in my side.
However, I could not figure out where I went wrong.
I appreciate your help on this.
Thank you guys for answering my question.
I solved myself. It was due to having FPPopoverController as in local variable. I needed to put as instance variable with strong property, otherwise the controller is deallocated by ARC. That made a popover frame is still visible but table view content inside of popover is dismissed.
I am not sure what FFPopoverController does but in case of a normal popover controller you can use popover delegate method "popoverControllerShouldDismissPopover" to restrict the disappearance of a popover like following:
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
return NO;
}
Surely, you need to declare UIPopoverControllerDelegate to the .h file of your view controller and set the "delegate" property of the popover controller to "self", for the above method to work.
I've got a UIPopoverController created programmatically which pops up with the content from a UIViewController from a .xib. The UIViewController contains a (grouped) UITableView and a UITableViewCell "prototype".
When The popover pops up, the cell prototype is duplicated for all cells needed. The number of cells exceeds the size of the popover, so I can scroll through all cells.
When the popover pops up, everything looks nice, the cell labels are all left aligned. As soon as I touch the tableview to scroll, all cell labels suddenly align to center. When I scroll the cells outside and back in, the are left aligned again. After I scrolled all cells outside for once, they keep left aligned for the rest of their lifetime. I have no idea what is causing this... there is nothing in my code that alters the alignment of the cells. Here's some code:
UIViewController *editPopoverView = [[[ComponentViewEmptyEditPopover alloc] initWithNibName:#"ComponentViewEmptyEditPopover" bundle:nil] autorelease];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:editPopoverView];
aPopover.delegate = self;
[aPopover presentPopoverFromRect:sender.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
From the popover viewcontroller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *theCell = nil;
switch (indexPath.section)
{
case 0:
theCell = [tableView dequeueReusableCellWithIdentifier:#"typeCell"];
if (theCell == nil)
{
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.typeCell];
theCell = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
}
switch (indexPath.row)
{
case 0:
[theCell.textLabel setText:#"Empty"];
break;
//
}
break;
}
return theCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1)
return 420;
return 44;
}
Any ideas why this is happening? I guess this is somehow related to cell reuse.
Update: Like I already guessed, it has to to with the reusing. When I do
theCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:#"theCell"];
everything works fine. However, I want to be able to change the design of the cell through interface builder...
Update 2: If I comment out the dequeueReusableCellWithIdentifier line, all cells will go back to center alignment after they scroll in.