prolonged tap on tableView header cell crashes the App - uitableview

I don't know whats happening but when I prolong my tap on a table view header cell the app crashes with Bad Excess Error. I am not registering any tapGestures in the viewController or in my custom tableViewCell class.
This is my code for my header cell
CustomTableViewCell = (CustomTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:#"headerCell"];
UIView *view = cell.contentView;
return view;

Ok after a bit of research found this little hack.
while (cell.contentView.gestureRecognizers.count) {
[cell.contentView removeGestureRecognizer:[cell.contentView.gestureRecognizers objectAtIndex:0]];
}
How to Implement Custom Table View Section Headers and Footers with Storyboard

Related

ios Tableview cell disappears when Selecting TextView

I have a tableview that has custom cells in it. The section header on the cell has a selectable textview.
When you double tap and select the textview then tap away from it... the cell literally disappears. But when I scroll completely so that the cell is out of visibility and go back then scroll back... the cell comes back.
Very confused as to why this is happening. Does anyone have any idea what would cause this issue???
Issue is specific to the Table view header section, if I have selectable textview in the other cells and tap away the cell doesn't disappear.
I think you are designed the View for header as a table view cell. The disappearing issue is may be due to two reasons
1.Please check the tableview and cell views scope you declared.If it is weak please make it as strong.
2.I will give u a sample code you need to declare in view for header delegate
If you returned cell instead of uiview it may happen.Please verify that one also.
static NSString *CellIdentifier = #"QuizCreation2HeaderTableViewCell";
QuizCreation2HeaderTableViewCell* sectionHeaderCell = (QuizCreation2HeaderTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView * headerView = [[UIView alloc] initWithFrame:sectionHeaderCell.frame];
[headerView addSubview:sectionHeaderCell];
return headerView;

xcode and storyboard: how build an user profile view

how can i build an user profile view like this (Periscope but is similar to many other apps).
It's a tableviewcontroller? If it is, how can i put the image of the user with background (it's in the first cell or above the tableview?)
I'd build it this way:
UIViewController with UITableView + custom UIView on top.
If you want to use already implemented libraries, check this out :
MGSpotyViewController
jcbannerView
Facade
They have pretty similar logic that's described in your question.
It is a custom tableviewcontroller. Everything is a cell but it is hard to create only using storyboard. you create a dynamic table view and ad 3 prototype cell for it (1: Blue cell, 2:Grey empty cell, 3: Option Cell). And create a controller and manage the cell with it like:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexpath.row== 0)
{
HeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:#"headerCell" forIndexPath:indexPath];
cell.name = "foo";
....
}
else if(indexpath.row ==1 || indexpath.row ==3)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"blankCell" forIndexPath:indexPath];
[cell setBackgroundColor:[UIColor greyColor]];
}else{
....
}
}
Looks like above is a header view, and below a table view.
If the above part scrolls off it is the table view's tableHeaderView. In this case you can use a UITableViewController.
Otherwise you will have to use a UIViewController with a UIView as the header and a UITableView below it, and you have to declare the table view delegate and datasource yourself.
You can achieved same UI with help of bringing UITableView and add UIView with blue background as tableHeaderView like as below.
UIView *headerView = [[UIView alloc] init...];
tableView.tableHeaderView = headerView;

Best way to create custom UITableview section header in storyboard

Current I am creating a prototype cell in storyboard and using this cell as a section header.
Inside tableView:viewForHeaderInSection: method, I am dequeuing the cell and returning it.
My section header cell has a UITextField and a UIButton in it.
When I tap on text field keyboard appears but as soon as focus is moved away from text field whole section header disappears.
This happens when I return the cell directly as section header view, but if I return a newly allocated UIView as section header view onto which cell is added as subview then everything works fine besides autoresizing masks.
Why header is disappearing?
I am not sure what could be the best thing todo here.
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
static NSString *CellIdentifier = #"SectionHeader";
SettingsTableViewCell *sectionHeaderCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//return sectionHeaderCell; // returning cell directly, section header disappears when focus is moved away from text field.
UIView * headerView = [[UIView alloc] initWithFrame:sectionHeaderCell.frame];
[headerView addSubView:sectionHeaderCell];
return sectionHeaderCell;//header view never disappears, but auto resizing masks do not work. Need to know how to set autoresizing masks to headerView so that it resizes correctly.
}
Prototype cell table views only allow you to design cells in the storyboard editor, not section headers and footers. Your attempt to use a UITableViewCell as the section header is a clever hack, but it's just not supported by the classes involved—UITableViewCell is not designed to be used for anything other than a table view cell. It could do a lot worse than the view disappearing or not being laid out correctly; UIKit would be well within its rights to fail an assertion, delete all the app's data, revoke your developer certificate, or set your house on fire.
If you want your code to function properly, your choices are to either create your section headers in code or to put them in a separate XIB file. I know that's not what you want to do, but those are the options you have.
I had the same issue and the fix was to return the cell's contentView like:
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
static NSString *CellIdentifier = #"SectionHeader";
SettingsTableViewCell *sectionHeaderCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
sectionHeaderCell.myPrettyLabel.text = #"Greetings";
sectionHeaderCell.contentView.backgroundColor = [UIColor whiteColor]; // don't leave this transparent
return sectionHeaderCell.contentView;
}
And you get the same autolayouted results as before, but without the disappearing.
I am sure you can use UITableViewCell as a section header, because UITableViewCell is subclass of UIView, so according to LSP
“objects in a program should be replaceable with instances of their
subtypes without altering the correctness of that program.”
In iOS 8, it's simple really. Just design your header the same way you design your cell. Everything is the same, you can put custom class and don't forget to add reuse identifier.
When it comes to use it in the code, just return that cell in tableView:viewForHeaderInSection method.
Don't forget to implement tableView:heightForHeaderInSection if you want to use fix height or tableView:estimatedHeightForHeaderInSection if the height depends on the cell intrinsic size.

Custom buttons in XIB used as Custom UITableViewCell don't respond to taps (ios7)

So here I am upgrading a working ios6 app to ios7, and now I can't receive taps or other actions on custom buttons (or other subviews) inside my tableviewcells.
Edit:
My code:
Here is where I deploy my PlaceCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"PlaceCell";
PlaceCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
if (!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"PlaceCell" owner:self options:nil];
cell = [nib lastObject];
cell.reuseIdentifier = cellIdentifier;
}
[cell configureCellWithPlace: [self.places objectAtIndex:indexPath.row]];
cell.delegate = self;
cell.userInteractionEnabled = YES;
return cell;
}
And then it is a normal custom cell with buttons which are connected to some actions by the interface.
It works perfectly with iOS6, but it does nothing with iOS7.
Thank you for your help.
Solved with:
[cell.contentView setUserInteractionEnabled: NO];
Put your button into cell's contentView.
This happens when your Cell's view in xib file is not a UITableViewCell, but only a UIView. Make sure that that the xib's top view is a UITableViewCell.
You can easily check it by looking into the first child of the main view inside the interface builder. If the first subview is not "Content View" then you should rebuild the cell with UITableViewCell on the top.
Also make sure that button is a subview of the "Content View".
I had a similar problem. I had dragged a UIView into the xib to use as my UITableViewCell. Even though I changed the classname to a subclass of a UITableViewCell in Interface Builder, the events on my buttons still didn't fire. Since it was originally a UIView, IB never knew about contentView and didn't add my controls to it.
Dragging a "real" UITableViewCell into the xib, changing its class to the one I wanted, and then rewiring up the IBOutlets fixed everything. Didn't need to mess with delaysContentTouches or other properties either.
Moral of the story: drag the right thing onto your xibs.
It seems to be that when you use interface builder to customize a cell subclass all the views added are added below the contentView. This is why setting userInteractionEnabled = NO on the content view works, because touch events are allow to pass through.
I used po [view recursiveDescription] with lldb to determine this.

UITableView cells not drawing until the cell is at the top of the screen

I am building a table where each cell of the UITableView is a UIViewController. I have three different UIViewControllers I need to show in three rows of the table. I set the row of each cell to match the size of the UIViewController so each row is a different height.
When the app first starts, only the UIViewController in the first cell shows up. The contents of the next row doesn't show up until I scroll the table so that the top of that row is at the top of the screen. Likewise if I scroll down slightly so that a row is slightly off the bottom of the screen, when I scroll back up a little, the row contents are gone.
Here's the code I'm using. Note: The controllers to are created in the viewdidload method
What am I missing? Thanks
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch(indexPath.section)
{
case 0:
{
[cell.contentView addSubview:patientInformationController.view];
break;
}
case 1:
{
[cell.contentView addSubview:labsController.view];
break;
}
case 2:
{
[cell.contentView addSubview:planController.view];
break;
}
default:
break;
}
}
return cell;
}
UITableViewController is a huge, high-level construct for efficiently managing entire screens of data and UI objects. UITableViewCell is a tiny, efficient, highly-optimized view class designed to be drawn and updated as fast as possible.
Do not, ever ever ever, add a UIViewController's view to the contentView of a UITableViewCell. A few labels, an image, maybe a small control such as a UISwitch or UITextView.
If you haven't already, start reading here.
If you want to associate your view controllers (patientInformationController, labsController) with a particular row of the table view, the proper method is to just set the cell label for that row to a human-readable string, such as #"Patient Information", or #"Labs", and then, when the row is selected, use a UINavigationController to push the proper view controller.
UINavigationController manages a stack of UIViewControllers. A UIViewController manages a single coherent interface, usually comprised of a bunch of cooperating views. UITableViewController is a subclass of UIViewController which manages a single UITableView. UITableView is a class which specializes in the lightning-fast rendering and presentation of tabular data, organized into sections and rows according to a delegate and data source that you provide. One of the capabilities of UITableView is to inform its delegate in the event of the user selecting a row of the UITableView, allowing the delegate to present, via a UINavigationController, a new UIViewController for the presentation to the user of yet more detail and functionality.
Hope this helps. Start reading.

Resources