Swift - TableView How To Create Expandable Section [duplicate] - iphone

This question already has an answer here:
Expandable Sections UITableView IndexPath SWIFT
(1 answer)
Closed 6 years ago.
I want to create a expandable section with swift. For example in the picture below, Microsoft Outlook IOS application has a expandable section.
When you click to the section , it seems like below.
Is this section needs extra code or xcode already has a feature for this? Thanks in advance.

You need to create a delegate for the custom section you have created, assign it to the ViewController and in the delegate method call this when the user taps on it.
insertRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation)
and when the user taps again on the section check if the section is open, if yes then call this method.
deleteRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation)
And don't forget to call tableView.reloadData() after these methods.

I've recently used the same in one of my project but it was in objective-c, i know one something which will help you. Please have a look,
Swift Expandable Section
I hoe it will helps you.
Thanks.

Related

CustomCell crash in UItableView [duplicate]

This question already has answers here:
"Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass
(31 answers)
Closed 9 years ago.
I have been using a customCell.xib with its own customCellClass within a UITableView,which is built without using autoLayout feature(since I need to make it work even on platforms prior to iOS6).
The UITableView fetches this custom made xib cell in its dataSource method.
The dilemma I'm facing is that the UITableView crashes abruptly 50 % of times I run it but executes and shows the tabeview perfectly rest of the times..
I m currently using XCode 4.5.
Here's the crash Log i receive ..
'Auto Layout still required after executing -layoutSubviews.
UITableViewCell's implementation of -layoutSubviews needs to call
super.'
This has been covered in some detail here, and it is not as simple as simply calling [super layoutSubviews];
"Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass
Try disabling 'translatesAutoresizingMaskIntoConstraints' on each of your views. Auto Layout is somehow being triggered, and that causes this bug on UITableView to pop up.
Your custom cell class implementation overrides layoutSubviews without calling super. That's right there in the crash log!

How to encapsulate Picker within UITableViewCell?

Anybody can give more detail about the answer to the question "How do I make a modal date picker that only covers half the screen?" which is answered by user eladleb.
#interface pickerCell : UITableViewCell
{
UITextField *txtTextField;
UIPickerView* dtpPicker;
}
especially step 2, 3, 4, anybody can elaborate in detail(i.e. which method...)? sample codes are highly appreciated. Thanks.
iOS has a UIActionSheet that is designed for uses just like that.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html
There is also an open source framework that will take a lot of the work out of putting the picker in an actionsheet. This way, when a user taps a cell, show the action sheet.
https://github.com/TimCinel/ActionSheetPicker

How to scroll the UITableviewcell scroll up when the keyboard appears? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Table View scroll when text field begin editing iphone
I have loaded many UITextFields in UITableview. Maximum i have 15 UITextFields in UITableView cells. I want to move(Scroll) up the the Cell when the Keyboard/UIActionSheet(UIPickerView) appears. Please suggest/guide me any sample code to solve this problem. Thanks in advance.
You can use the sample code to take some hint.
https://github.com/michaeltyson/TPKeyboardAvoiding
I have used it in my projects as well.Hope it helps
Please try below code in -textFieldShouldBeginEditing ....
self.tblView.frame= CGRectMake(self.tblView.frame.origin.x, self.tblView.frame.origin.y, self.tblView.frame.size.width, self.tblView.frame.size.height - 190);
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:nIndex inSection:nSectionIndex];
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
Thanks
Check out the below link from apple documentation with complete explanation and required code
They have talked about for registering for the keyboard appear and disappear notification and alter the rect of your underlaying UIView in the notification method for more go through the below URL.
Moving Content That Is Located Under the Keyboard

How can I have each row of a UITableView direct the user to a new page? [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Change view when tableview cell is pressed?
I have a UITableView with several rows, and I'd like to have it so that tapping on each row would take you to a different view. How can I do this?
if you have the user id stored in the same array as your TableView data you could well use indexPath to access this information and pass it off to another control like a UIViewController. eg.
NSDictionary *selectedUser = [MyTableViewDataArray objectAtIndex:indexPath.row];
MyUserViewController *userVController = [[MyUserViewController alloc] initWithUser:selectedUser];
you could then push this viewcontroller onto the stack
[self.navigationController pushViewController:userVController animated:YES];
[userViewController release];
obviously this is a pseudo example but should help you.
Tim
Create a new project from the Navigation-based application template and XCode will generate you the example code.

how do I know when UIKeyboard Join button is tapped?

How do I know when a user taps on the Join button on the UIKeyboard?
Also can this text be changed? I know there are several built options but I nee done that says 'Login' if I can.
I'm not a big fan of using UITextField delegate just for knowing when keyboard entry is completed by pressing the "return" on the keyboard (whatever it's labeled). UITextField actually works well with a Target/Action pattern which is much simpler and far more direct than using the delegate for this.
I've pointed this out before in an answer to "How to call a method when the Done Button in the KeyBoard is Clicked?". Please take a look at that for the details of using the traditional target/action pattern to know when keyboard entry is complete. Unfortunately, Apple's documentation isn't as clear is it could be on this subject.
UITextField delegate has its place, but if all you need is to know when entry is complete then using the delegate likely isn't the best approach. Use target/action.
For the UIReturnKeyType choices, see the returnKeyType property in the UITextInputTraits Protocol Reference.
You should set your delegate of your UITextField (I'm assuming that's a UITextField) and check for that delegate call :
- (BOOL)textFieldShouldReturn:(UITextField *)textField
Also, you return a BOOL to tell the UITextField to do its default behavior or not. You can check the documentation here.
Also, the options Apple gives you for the UIReturnKeyType are your only options.