UIView animation is cancelled at the end - ios

I have a cell with a UIView with a white backgroundColor. I want to change background color with an animation. I use this method in -tableView:tableView didSelectRowAtIndexPath:indexPath :
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionOverrideInheritedCurve animations:^(void){
([cell viewWithTag:20]).backgroundColor = [UIColor orangeColor];
} completion:NULL];
The animation begin correctly, but at the end, the UIView becomes white again.
How can I fix that ?
edit: full code
#pragma mark - Table view
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 71;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _arFiles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"RecentCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
((UILabel*)[cell viewWithTag:2]).text = [[_arFiles objectAtIndex:indexPath.row]objectForKey:KEY_FILE_NAME];
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 10);
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = ((UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath]);
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionOverrideInheritedCurve animations:^(void){
([cell viewWithTag:20]).backgroundColor = [UIColor orangeColor];
} completion:NULL];
}

subclassing the cell may work as u expected, hear is the code try it out in custom cell
do somthing like below
//in CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIView *view = [[UIView alloc]initWithFrame:CGRectZero];//your view
view.tag = 100;
[self addSubview:view];//add to cell
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
UIView *view = [self viewWithTag:100];
if(selected)
{
//animation when selected
[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionOverrideInheritedCurve animations:^(void){
view.backgroundColor = [UIColor orangeColor];
} completion:NULL];
}
else
{
//this is for when deselect if u want color in same sate then set it
}
// Configure the view for the selected state
}
- (void)layoutSubviews
{
[super layoutSubviews];
UIView *view = [self viewWithTag:100];//get the view
view.frame = CGRectMake(5, 5, 100, 30);//setting the frame
}
in your controller just use this custom cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if(cell == nil)
{
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//dont add any animation hear becz u already added in custom cell
// [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionOverrideInheritedCurve animations:^(void){
// ([cell viewWithTag:100]).backgroundColor = [UIColor orangeColor];
// } completion:NULL];
}

I have solve my problem:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = ((UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath]);
[self performSelector:#selector(launchAnimation:) withObject:cell afterDelay:0.1];
}
-(void)launchAnimation:(UITableViewCell*)cell{
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionOverrideInheritedCurve animations:^(void){
([cell viewWithTag:20]).backgroundColor = [UIColor orangeColor];
} completion:NULL];
}

Related

Load UIWebView in UITableViewCell and Make UITabViewCell's height as per the content of UIWebview

I am working on a project, where I have a UITableViewCell containing UIImageView, UILable and UIWebView.
I need to open a webview (with added HTML string in it) on didselectrowatIndexpathmethod and cell height should be increase to the content size of UIWebView. I have tried following code. But this is not working as per the expectation. Kindly advice.
#pragma mark - Table view data source
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [faqContentArray count];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
FAQCell *cell = (FAQCell*)[tableView cellForRowAtIndexPath:indexPath];
[cell.faqContentWebView loadHTMLString:[[faqContentArray objectAtIndex:indexPath.row] objectForKey:#"content"] baseURL:nil];
NSString *wrappedText = [[faqContentArray objectAtIndex:indexPath.row] objectForKey:#"content"];
cell.faqContentWebView.frame=CGRectMake(8.0f, 43.0f, 304.0f, [self minHeightForText:wrappedText]);
[self rotateIconToExpanded:cell.faqImage];
[self.faqTableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
}
//-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
// FAQCell *cell = (FAQCell*)[tableView cellForRowAtIndexPath:indexPath];
//
// [cell.faqContentWebView loadHTMLString:#"" baseURL:nil];
// cell.faqContentWebView.frame=CGRectMake(8.0f, 43.0f, 304.0f, 5);
// [self rotateIconToCollapsed:cell.faqImage];
// [self.faqTableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationTop];
//}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FAQCell *cell = (FAQCell*)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (!cell) {
[tableView registerNib:[UINib nibWithNibName:#"FAQCell" bundle:nil] forCellReuseIdentifier:#"MyCell"];
cell = (FAQCell*)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
cell.faqContentWebView.delegate=self;
cell.faqContentWebView.layer.cornerRadius = 0;
cell.faqContentWebView.userInteractionEnabled = NO;
cell.faqContentWebView.multipleTouchEnabled = YES;
cell.faqContentWebView.clipsToBounds = YES;
cell.faqContentWebView.scalesPageToFit = NO;
cell.faqContentWebView.scrollView.scrollEnabled = NO;
cell.faqContentWebView.scrollView.bounces = NO;
cell.faqContentWebView.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
cell.faqTitleLbl.text=[[faqContentArray objectAtIndex:indexPath.row] objectForKey:#"title"];
cell.faqImage.image=[UIImage imageNamed:#"downarow.png"];
return cell;
}
- (void)rotateIconToExpanded:(UIImageView *)iconImage {
[UIView beginAnimations:#"rotateDisclosure" context:nil];
[UIView setAnimationDuration:0.2];
iconImage.transform = CGAffineTransformMakeRotation(M_PI * 2.5);
[UIView commitAnimations];
}
- (void)rotateIconToCollapsed:(UIImageView *)iconImage {
[UIView beginAnimations:#"rotateDisclosure" context:nil];
[UIView setAnimationDuration:0.2];
iconImage.transform = CGAffineTransformMakeRotation(M_PI * 2);
[UIView commitAnimations];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
id celll = [self tableView:tableView cellForRowAtIndexPath:indexPath];
FAQCell *cell=(FAQCell *)celll;
[cell setNeedsLayout];
[cell layoutIfNeeded];
NSLog(#"height------>%f",[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height);
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
You will need to calculate (and possibly monitor) the size of your content in the UIWebView. One way is through UIWebView's UIScrollView:
CGFloat webViewContentHeight = myWebView.scrollView.contentSize.height;
another is:
CGFloat webViewContentHeight = [myWebView stringForEvaluatingJavaScript:#"document.body.offsetHeight"].floatValue;
When you retrieve that height is important, you will want it once the content of the UIWebView has finished loading (once it has you can invalidate/update the constraints of your UITableViewCell, for example).

Nested UITableViewController does not show any cells

I've added a UITableViewController to my main view controller using method from Apple docs:
- (void)viewWillAppear:(BOOL)animated {
myTableViewController = [MyTableViewController new];
[self displayContentController:myTableViewController];
}
- (void)displayContentController:(UIViewController *)viewController; {
[self addChildViewController:viewController];
viewController.view.frame = self.view.bounds;
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
}
and I wanted to display some example cells in this controller:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
(I don't think I need any more configuration as it is UITableViewController, not UITableView)
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
cell.textLabel.text = #"Under development";
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
But all I can see is just empty cells (I've also tried to change background color to make sure it's not just the while label color):
After few hours I have no idea what I did wrong. Do you have any idea what am I missing?
You have to used it:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:#"cell"];
if(!cell)
{
cell=[[UITableViewCell alloc]init];
}
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.text = #"Under development";
return cell;
}
Try it:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return Table_Arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:#"subwaysurfer"];
if(!cell)
{
cell=[[UITableViewCell alloc]init];
}
UIImageView *imgg;
UILabel *txt;
UIImageView *Acc_img;
imgg=[[UIImageView alloc]initWithFrame:CGRectMake(10,5, 50, 50)];
imgg.image = [UIImage imageNamed:[imageArr objectAtIndex:indexPath.row]];
cell.highlighted=YES;
cell.backgroundColor=[UIColor clearColor];
txt=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, self.view.frame.size.width-80, 60)];
txt.numberOfLines = 3;
txt.text=[Table_Arr objectAtIndex:indexPath.row];
txt.backgroundColor=[UIColor clearColor];
// txt.textColor=[UIColor colorWithRed:66.0/255.0 green:51.0/255.0 blue:57.0/255.0 alpha:1.0];
txt.textColor=[UIColor colorWithRed:44.f/255.f green:78.f/255.f blue:134.f/255.f alpha:1];
txt.font=[UIFont fontWithName:#"AvenirNextCondensed-Medium" size:16.0];
Acc_img=[[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width-40, 20, 20, 20)];
Acc_img.image=[UIImage imageNamed:#"arrow.png"];
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){
imgg.frame = CGRectMake(10, 5, 80, 80);
txt.frame = CGRectMake(120, 10, self.view.frame.size.width-160, 70);
Acc_img.frame = CGRectMake(self.view.frame.size.width-80, 25, 40, 40);
txt.font=[UIFont systemFontOfSize:28.0];
}
[cell addSubview:imgg];
[cell addSubview:txt];
[cell.contentView addSubview:Acc_img];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
// fixed font style. use custom view (UILabel) if you want something different
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){
return 90;
}
else{
return 60;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
}
Ok, problem solved. It appears, that even using UITableViewController which has built-in property tableView it is necessary to initialise the tableView (or at least it did help me).
self.tableView = [UITableView new];

UITableView with multiple sections and accessoryType

This is my functions for my table View.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.categories count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return #"test";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"%d", self.collections.count);
return [self.collections count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
switch ([indexPath section])
{
case 0:
self.myList = self.collections;
break;
}
cell.textLabel.text = self.collections[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 48;
}
Actually, with this code, my table view show all the section and cells in the same view.
However, I would like a table view which show, at first time, a row with my title of section.
When i click on the row where there is my title of section, i would like to show the cells which are in the section. How can i do that?
Do i need 2 tableViews?
You should have to take two uitableview in that delegate will be same after that you should have to use this code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:#"%#",indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==Nil)
{
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
if (isDeptSelected)
{
//[cell.imageView setImage:[UIImage imageNamed:#"Department.png"]];
cell.textLabel.text = [[arrDept_Detail valueForKey:#"dep_Name"]objectAtIndex:indexPath.row];
}
else if (isEmpSelected)
{
[cell.imageView setImage:[UIImage imageNamed:#"Emp_Images"]];
cell.textLabel.text = [[arrEmp_Detail valueForKey:#"emp_Name"]objectAtIndex:indexPath.row];
}
// cell.textLabel.text=[[arrDept_Detail objectAtIndex:indexPath.row]valueForKeyPath:#"dep_Name"];
[cell setBackgroundColor:[UIColor brownColor]];
[cell.textLabel setTextColor:[UIColor greenColor]];
[cell.textLabel setFont:[UIFont fontWithName:#"Georgia-Bold" size:16]];
cell.textLabel.highlightedTextColor=[UIColor purpleColor];
[self.view setBackgroundColor:[UIColor brownColor]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (isDeptSelected)
{
isDeptSelected=false;
isEmpSelected=true;
[btnDoneclick setHidden:NO];
[self.view addSubview:btnDoneclick];
EmpInDepTableView=[[UITableView alloc]initWithFrame:CGRectMake(160, 284,0, 0)];
[EmpInDepTableView setDelegate:self];
[EmpInDepTableView setDataSource:self];
[EmpInDepTableView setHidden:NO];
[EmpInDepTableView setBackgroundColor:[UIColor brownColor]];
EmpInDepTableView.layer.borderWidth=3.0f;
EmpInDepTableView.layer.cornerRadius=10.0f;
[self.view addSubview:EmpInDepTableView];
self.tabBarController.tabBar.userInteractionEnabled=NO;
UITableViewCell *cell=[Dept_TableView cellForRowAtIndexPath:indexPath];
DeptId=[Dep_Detail fetchDeptId_DeptName:cell.textLabel.text];
arrEmp_Detail = [[Emp_Detail fetchEmp_By_DeptId:DeptId]mutableCopy];
[UITableView animateWithDuration:0.6 animations:^
{
[EmpInDepTableView setFrame:CGRectMake(0, 64,320, 430)];
[btnDoneclick setFrame:CGRectMake(0,490,320,29)];
}completion:^(BOOL finished)
{
[EmpInDepTableView reloadData];
}];
}
else if (isEmpSelected)
{
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor brownColor]];
return view;
}
-(IBAction)btnDoneclicked:(id)sender
{
[EmpInDepTableView reloadData];
isDeptSelected=true;
isEmpSelected=false;
[btnDoneclick setHidden:YES];
self.tabBarController.tabBar.userInteractionEnabled=YES;
[UITableView animateWithDuration:0.6 animations:^
{
[EmpInDepTableView setFrame:CGRectMake(160, 284, 0, 0)];
[btnDoneclick setFrame:CGRectMake(160, 284, 0, 0)];
[self.view setBackgroundColor:[UIColor brownColor]];
}completion:^(BOOL finished)
{
}];
}

UITableview tablecell separator missing when the tablecell is selected programatically

#implementation TestTableViewCell
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
self.selectedBackgroundView = [[UIView alloc] init];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
if(highlighted || self.selected)
{
self.labelTest.tintColor = self.tintColor;
self.labelTest.text = #"HighLighted";
}
else
{
self.labelTest.tintColor = [UIColor redColor];
self.labelTest.text = #"Not HighLighted";
}
}
#end
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
tableView.separatorColor = [UIColor redColor];
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"testCell"];
if (indexPath.row == 5) {
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
return cell;
}
This is my code. If the row is 5 programmatically select the cell using selectRowAtIndexPath. When I do this, the tableseperator is missing in 7.1 But the same code works fine in 7.0
Not sure why the separator is missing in 7.1
Actually the problem was setting the selectedbackground. It works fine in iOS7 but have some issues in 7.1

UIPickerView in UITableView

First of all: I know that some people already posted topics like that, but nobody gave a clear answer in all those topics.
I have a settings-UITableView in my application. Now i want to add a TableViewCell where i can choose between some numbers with a UIPickerView.
In the tableView didSelectRowAtIndexPath method i created the if statement for the right cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 1){
}
}
How can i add a UIPickerView for this cell? It should slide up from the bottom and it would be nice if there is something like a "done" button.
Have you seen the sample program released with iOS 7 called DateCell? It uses a UIDatePicker, but I found it pretty straightforward to adapt it to a regular UIPickerView.
It does exactly what you're describing: edit a UITableViewCell with a picker that opens directly under the row you're editing.
This is also based on your other question, so I am including those functionalities here as well (i.e. the switch).
In your YourTableViewController.h
set:
#interface YourTableViewViewController : UITableViewController <UIPickerViewDataSource, UIPickerViewDelegate>
In your YourTableViewController.m
Paste this code:
#interface YourTableViewViewController ()
#property NSInteger toggle;
#property (strong, nonatomic) UIPickerView *pickerView;
#end
#implementation YourTableViewViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.toggle = 0;
self.pickerView = [[UIPickerView alloc] initWithFrame:(CGRect){{0, 0}, 320, 480}];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerView.center = (CGPoint){160, 640};
self.pickerView.hidden = YES;
[self.view addSubview:self.pickerView];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 2;
}
- (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];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if(indexPath.row == 0)
{
[cell.contentView addSubview:self.mySwitch];
}
if(indexPath.row == 1)
{
cell.textLabel.textColor = [UIColor darkGrayColor];
if(self.toggle == 0)
{
cell.textLabel.text = #"Choose a number";
}
else
{
cell.textLabel.text = #"Cancel";
}
}
// Configure the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 1)
{
if(self.toggle == 0)
{
self.toggle = 1;
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:YES];
[self bringUpPickerViewWithRow:indexPath];
}
else
{
self.toggle = 0;
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:YES];
[self hidePickerView];
}
}
}
- (void)bringUpPickerViewWithRow:(NSIndexPath*)indexPath
{
UITableViewCell *currentCellSelected = [self.tableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.hidden = NO;
self.pickerView.center = (CGPoint){currentCellSelected.frame.size.width/2, self.tableView.frame.origin.y + currentCellSelected.frame.size.height*4};
}
completion:nil];
}
- (void)hidePickerView
{
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.center = (CGPoint){160, 800};
}
completion:^(BOOL finished)
{
self.pickerView.hidden = YES;
}];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.toggle = 0;
[self.tableView reloadData];
[self hidePickerView];
NSLog(#"row selected:%ld", (long)row);
}
- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [NSString stringWithFormat:#"%d", row+1];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 10;
}
#end
Tested.
Addendum:
Also, in your storyboard, change the separator for YourTableView to None (looks better in your case here).
Table View Separator:
in viewDidLoad, add:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
And in bringUpPickerViewWithRow
after:
UITableViewCell *currentCellSelected = [self.tableView cellForRowAtIndexPath:indexPath];
add:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView setNeedsDisplay];
And lastly, in hidePickerView, add:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[self.tableView setNeedsDisplay];
Create custom ViewController that include UIPickerView and Done
button.
Add it as subview on your tableview. (Place it bottom so
that it does not visible).
Once user click appropriate cell, you
can animate picker-view from bottom.
Once user select an item
animate and position it to bottom.
I have done above steps for same purpose. If you want I can send custom controller that include UIPickerView and done button.

Resources