I have a UITableView and view above it. Sometimes I have a lot of content so this header should be scrolled up and have to be immediatelly shown when I scroll down (like Facebook app). And I have a pull to refresh control so when I pulled down to pull to refresh my header UIView should be above UITableView (if I use a UITableViewHeaderit moves down with UITableView). What can you advice? I've really stucked. Thanks in advance.
#pragama mark delegate UIScrollView
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self scrollViewAnimation:scrollView];
}
-(void)scrollViewAnimation:(UIScrollView *)scrollView{
if (scrollView==YourtableViewName) {
[YourtableViewName layoutIfNeeded];
if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].y > 0) {
NSLog(#"Scrolling Up");
[UIView animateWithDuration:0.25 animations:^{
viewTop_topConstraint.constant = 0;
[self.view updateConstraintsIfNeeded];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
} else if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].y < 0) {
NSLog(#"Scrolling Down");
if (dataArray.count>4) {
[UIView animateWithDuration:0.25 animations:^{
viewTop_topConstraint.constant = -120;
[self.view updateConstraintsIfNeeded];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
}
}
I tried a little to implement what you wanted. And I came up with this piece of code. But you might have to do a few tweaks yourself. I just set sectionHeight variable to 60 and used that to return that as section height. Make sure you set this variable to 60 (or the height of your view) in viewDidLoad or viewWillAppear method. And return the UIView you want to show above your UITableView in viewForHeaderInSection method. Let me know if you have any confusions regarding the code.
#pragma mark - TableView Data Source Events
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"DeliveryPackageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = #"1";
return cell;
}
#pragma mark - TableView Delegate Events
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,sectionHeight)];
[view setBackgroundColor:[UIColor lightGrayColor]];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return sectionHeight;
}
#pragma mark - Srcoll View Delegates
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
self.initialContentOffset = scrollView.contentOffset.y;
self.previousContentDelta = 0.f;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat prevDelta = self.previousContentDelta;
CGFloat delta = scrollView.contentOffset.y - self.initialContentOffset;
if (delta > 0.f && prevDelta <= 0.f) {
// started scrolling positively
if(sectionHeight != 0)
{
sectionHeight = 0;
[tableView reloadData];
}
} else if (delta < 0.f && prevDelta >= 0.f) {
// started scrolling negatively
if(sectionHeight == 0)
{
sectionHeight = 60;
[tableView reloadData];
}
}
self.previousContentDelta = delta;
}
Related
How top expand collapse custom cell tableview and expanding the cell must be dynamic height in iOS objective c?
viewcontroller having custom tableview cells when click on the cell,cell must be expand/collapse having one view and display data in that view and height must be dynamic
You'll have to maintain a state (expanded/not expanded) for the custom table view cell. Every time it's tapped you make the necessary changes in the UI and toggle the state. You can then call
reloadData()
or
-(void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation;
You can also calculate and set the new height of the cell and the reload function will take care of the animation.
You used tableview then easy manage expand and collapse custom cell tableview and expanding with animation.
Follow code for expand and collapse.
.h File
BOOL currentlyExpanded;
NSMutableIndexSet *expandedSections;
.m File
- (void)viewDidLoad
{
if (!expandedSections)
{
expandedSections = [[NSMutableIndexSet alloc] init];
}
}
Use Tableview Delegate and Datasource method..
#pragma mark - Tableview Delegate -
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
{
return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self tableView:tableView canCollapseSection:section])
{
if ([expandedSections containsIndex:section])
return 6; //return your array count..
else
return 1;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
;
}
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
//Display your dynamic cell contain..
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
NSInteger section = indexPath.section;
currentlyExpanded = [expandedSections containsIndex:section];
NSInteger rows;
if (currentlyExpanded)
{
rows = [self tableView:tableView numberOfRowsInSection:section];
[expandedSections removeIndex:section];
}
else
{
[expandedSections addIndex:section];
rows = [self tableView:tableView numberOfRowsInSection:section];
}
// Animation when cell expand and collapse
if(currentlyExpanded)
{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
CGFloat startRadians, endRadians;
startRadians = M_PI/2;
endRadians = 0.0f;
btnArrow.layer.affineTransform = CGAffineTransformMakeRotation(startRadians);
[UIView animateWithDuration:0.3f animations:^{
btnArrow.layer.affineTransform = CGAffineTransformMakeRotation(endRadians);
}completion:^(BOOL finished){
}];
}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[btnArrow setTransform:CGAffineTransformRotate(btnArrow.transform, M_PI/2 )];
}completion:^(BOOL finished){
}];
}
}
}
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).
I am trying to simultaneously animate a custom UITableViewCell and the UITableView that contains it.
When clicked, the subviews of the UITableViewCell slightly re-arrange such that the height of the cell increases. I want the re-arrangement within the cell to happen concurrently with the resizing of the UITableView's slot for that cell, so that it doesn't overlap with the cell below it.
When clicked again, the reverse is to happen.
This is what I've tried so far.
The UITableView
When the UITableView is clicked, I use didSelectRowAtIndexPath to update a selectedPath property:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.selectedPath && indexPath.row == self.selectedPath.row) {
self.selectedPath = nil;
} else {
self.selectedPath = indexPath;
}
[tableView reloadData];
}
Note, it calls reloadData, which triggers each visible cell to re-fetch the prototype and configure it based on whether it is selected or not:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
QueueItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"QueueCell" forIndexPath:indexPath];
[cell setImage:[UIImage imageNamed:[self.imageList objectAtIndex:indexPath.row]]];
if (self.selectedPath && indexPath.row == self.selectedPath.row) {
[cell makeSelected:YES];
} else {
[cell makeSelected:NO];
}
return cell;
}
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath {
CGFloat height = 210;
if (indexPath.row == [self.imageList count] - 1) {
height += 10;
}
if (self.selectedPath && indexPath.row == self.selectedPath.row) {
height += 35;
}
return height;
}
The UITableViewCell subclass
In the custom cell class, its animation happens when it is made selected or not selected:
- (void)makeSelected:(BOOL)selected {
if (selected) {
[UIView animateWithDuration:0.5 animations:^{
self.customImage.frame = CGRectMake(5, 5, 310, 210);
}];
} else {
[UIView animateWithDuration:0.5 animations:^{
self.customImage.frame = CGRectMake(10, 10, 300, 200);
}];
}
}
What is happening
The table view immediately snaps to the new the allotted height for the cell, and then the cell's contents slowly animate to the new state. I want the two things to happen concurrently, and smoothly.
You might want to call
[UIView animateWithDuration:0.5 animations:^{
[self.tableView reloadData];
}];
and re-write the custom cell as following:
- (void)makeSelected:(BOOL)selected {
if (selected) {
self.customImage.frame = CGRectMake(5, 5, 310, 210);
} else {
self.customImage.frame = CGRectMake(10, 10, 300, 200);
}
}
I hope it helps.
try this... reload particular cell insteade
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:selectedRowIndexPath inSection:section];
// Add them in an index path array
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, nil];
// Launch reload for the two index path
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
You need to reload particular cell while tap use like this..
- (void)makeSelected:(BOOL)selected {
if (selected) {
self.customImage.frame = CGRectMake(5, 5, 310, 210);
} else {
self.customImage.frame = CGRectMake(10, 10, 300, 200);
}
}
Declare BOOl isSelect; as Global
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.selectedPath && indexPath.row == self.selectedPath.row) {
isSelect = NO;
} else {
self.selectedPath = indexPath;
isSelect = YES;
}
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
QueueItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"QueueCell" forIndexPath:indexPath];
[cell setImage:[UIImage imageNamed:[self.imageList objectAtIndex:indexPath.row]]];
if (self.selectedPath && indexPath.row == self.selectedPath.row && isSelect) {
[cell makeSelected:YES];
} else {
[cell makeSelected:NO];
}
return cell;
}
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath {
CGFloat height = 210;
if (indexPath.row == [self.imageList count] - 1) {
height += 10;
}
if (self.selectedPath && indexPath.row == self.selectedPath.row && isSelect) {
height += 35;
}
return height;
}
It reload the cell with animation.. I hope it will help you.. Now you check it will work as you want...
I have an UITableView where in the header part there are multiple headerSection available. The default height is 56. Now I want to change a particular headerSection height to 40 whenever I click on the particular section's button. the click triggers a method(sectionOpened:) which helps to change the height. But at that time, the other headerSection's height should remain 56. How do I do that? My attempt so far:
should
float headerSectionHeightDefault;
- (void)viewDidLoad
{
[super viewDidLoad];
headerSectionHeightDefault=56;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return headerSectionHeightDefault;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
headerView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 640.0f, 0.0f)];
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(15, 0, 300, 40)];
img.image = [UIImage imageNamed:#"menu_btn7.png"];
[headerView addSubview:img];
return headerView;
}
- (void) sectionOpened : (NSInteger) section
{
[menulistTable beginUpdates];
if(section==0)
{
headerSectionHeightDefault=40;
}
else
{
headerSectionHeightDefault=56;
}
[menulistTable endUpdates];
self.openSectionIndex = section;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return headerSectionHeightDefault;
}
by using this code you are returning height of the section to 40(i.e headerSectionHeightDefault), so what you have to do set the height for each section and return them individually.
I worked on same scenario and achieved by following code
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section==0)
return headerHeight;
if (section==1)
return headerHeight1;
if (section==2)
return headerHeight2;
if (section==3)
return headerHeight3;
if (section==4)
return headerHeight4;
if (section==5)
return headerHeight5;
if (section==6)
return headerHeight6;
}
-(void)changeHeight {
UIView *headerSectionView = (UIView *)[mainTable viewWithTag:currentSectionIndex+1];
[mainTable beginUpdates];
if (currentSectionIndex ==1)
headerHeight= updatedValue;
else if (currentSectionIndex==2)
headerHeight1= updatedValue;
else if (currentSectionIndex==3)
headerHeight2= updatedValue;
else if (currentSectionIndex==4)
headerHeight3= updatedValue;
else if (currentSectionIndex==5)
headerHeight4= updatedValue;
else if (currentSectionIndex==6)
headerHeight5= updatedValue;
[mainTable endUpdates];
}
instead of tableview update, try reloading the tableview after you changed the value of headerSectionHeightDefault.
- (void) sectionOpened : (NSInteger) section
{
if(section==0)
{
headerSectionHeightDefault=40;
}
else
{
headerSectionHeightDefault=56;
}
self.openSectionIndex = section;
[menulistTable reloadData];
}
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.