I have added a footer to the UITableView in plain style if the user clicks the textfield of last cell the tableview is not scrolling
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection: (NSInteger)section{
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[view setBackgroundColor:[UIColor blackColor]];
return view;
}
if it is a sectioned table this works, please help
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if(textField == yourTextField){ /// here write name of your Textfield in which you want to scroll tableview
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
yourTableView.frame = CGRectMake(yourTableView.frame.origin.x, -160, yourTableView.frame.size.width, tblContactUS.frame.size.height);
[UIView commitAnimations];
}
return YES;
}
and put your TableView with previous frame then use bellow method
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
if(textField == yourTextField){ /// here write name of your Textfield in which you want to scroll down tableview
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
yourTableView.frame = CGRectMake(yourTableView.frame.origin.x, 0, yourTableView.frame.size.width, tblContactUS.frame.size.height);
[UIView commitAnimations];
}
return YES;
}
i hope this help you...
Related
I have one table view and one imageview, each one takes half of the screen.
I am trying to animate an image view when the user swipes on the imageview and when table cell is selected.
I use this code:
#interface X()
#property (strong, nonatomic) IBOutlet UIImageView *ImagePreview;
#property (strong, nonatomic) IBOutlet UITableView *table;
#end
#implementation X
- (void)handleGestureRight:(UISwipeGestureRecognizer *)sender {
[self ShowAnimation:_ImageGalaryPreview];
}
-(void)ShowAnimation:(UIImageView *)view{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];
[UIView commitAnimations];
}
#end
It works perfect when I call it after the swipe but when I call it from UITableView class instance it does not work!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self ShowAnimation:_ImageGalaryPreview];
}
Can anyone tell me why ?!
Use your calling method as given below,It will definitely work.
-(void)stuff
{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:ـImagePreview cache:NO];
[UIView commitAnimations];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSelectorOnMainThread:#selector(stuff) withObject:nil waitUntilDone:NO];
}
you just need to pass the view of tableview in place of imageView....check it works.. Enjoy
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: tableView cache:NO];
[UIView commitAnimations];
}
Nothing happens when the user taps a table row because none of the lines in the didSelectRowAtIndexPath method includes anything that is related to indexPath.row. Maybe, try something like the following.
#interface ViewController () {
NSInteger selectedrow;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *selectedIndexPath = [table indexPathForSelectedRow];
selectedrow = indexPath.row;
if (indexPath.row >= 0) {
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
...
...
ImagePreview = ... [array objectAtIndex:selectedrow]...
}
}
- (void)viewDidLoad {
selectedrow = -1;
}
Still, I don't know how your code has anything to do with UIImageView.
thanks for your response also I solve it with this code
[self performSelectorOnMainThread:#selector(stuff) withObject:nil waitUntilDone:NO];
thanks to #Hercules :)
I´m working on a IRC client for iPhone and I am having problems with my UITableView.
First I resized the tableview so that a toolbar and the keyboard will fit on the screen as the user is typing a message. Looking like this:
But the problem is that when the user is done typing and wants to send the message (send to stream and add to the tableview) the tableview is resized and the toolbar is put at the bottom but the keyboard remain, I do NOT which the textfield to resign first responder, I want to keep the keyboard and toolbar where its at before and after pressing the send button. Looking like this:
This is some of my code:
-Resizing the windows
// Keyboard will show
- (void)keyboardWillShow {
[UIView animateWithDuration:0.25 animations:^{
[self.tableView setFrame:CGRectMake(0, 0, 320, 177)];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.toolBar setFrame:CGRectMake(0, 177, 320, 43)];
}];
}
// Keyboard will hide
- (void)keyboardWillHide {
[UIView animateWithDuration:0.25 animations:^{
[self.tableView setFrame:CGRectMake(0, 0, 320, 481)];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.toolBar setFrame:CGRectMake(0, 393, 320, 43)];
}];
}
-Adding element to the tableview
// Retrieve the sender and the message from the input and add it to the data context
- (void)addMessage:(NSString *) input isSender: (BOOL) sender {
Message *messageToBeAdded = [[Message alloc] init];
[messageToBeAdded setIsSender:sender];
NSArray *arr = [input componentsSeparatedByString:[NSString stringWithFormat:#"PRIVMSG %# :",[connection channel]]];
[messageToBeAdded setMessage:[arr objectAtIndex:1]];
arr = [input componentsSeparatedByString:#"!"];
if (sender) {
[messageToBeAdded setSender:[connection nick]];
} else {
NSString *tmp = [arr objectAtIndex:0];
[messageToBeAdded setSender:[tmp substringWithRange:NSMakeRange(1, [tmp length]-1)]];
}
[_messageList addObject:messageToBeAdded];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[_messageList count]-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
I´ve looked everywhere and I´m certain that it has to do with the add part of the tableview. I would appreciate any help or guidance.
Thank you!
EDIT:
I have just realized that is has to do with the use of a custom cell. I created a new project and tried to simulate what I have done step-by-step. And everything worked fine up too the point where I used a custom cell with an UILabel. The UILabel was connected to the UITableViewCell class with an outlet and this is where the problem occurred.
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
#end
Any thought what could be wrong here?
I am guessing that you have a UITextField in your Toolbar. Try...
[aTextField resignFirstResponder];
... when you handle hitting the the send/return button.
The text field controls the keyboard so resignfirstresponder sends a message to the keyboard to remove itself. Does the band move to the bottom of the screen or is removed after the send button is pressed. Either way do what Michael said to do and once the keyboard disappears you will know what happens to the banner. I hope this helps!
You can use UITextFieldDelegate -
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
}
Or if you have IBOutlet of textField then in 'Keyboard will hide' call resignFirstResponder
// Keyboard will hide
- (void)keyboardWillHide {
[self.myTextField resignFirstResponder];
[UIView animateWithDuration:0.25 animations:^{
[self.tableView setFrame:CGRectMake(0, 0, 320, 481)];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.toolBar setFrame:CGRectMake(0, 393, 320, 43)];
}];
}
How to animate custom picker view like actionsheet?
UIView *view = [[[UIView alloc]initWithFrame:CGRectMake(0,300,320,300)] autorelease];
view.backgroundColor = [UIColor brownColor];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:[self view] cache:YES];
[view setFrame:CGRectMake(0.0f,300.0f,320.0f,325.0f)];
[UIView commitAnimations];
Just like you did:
UIView *view=[[[UIView alloc]initWithFrame:CGRectMake(0,460,320,300)]autorelease];
view.backgroundColor=[UIColor brownColor];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:[self view] cache:YES];
[view setFrame:CGRectMake(0,0,320,300)];
[UIView commitAnimations];
But have a look at CGRect. Its (x,y,width,height). So you have to use the second parameter (y position) to animate the vertical position of your view.
Correct answer is this for custom picker view but it won't animate like action sheet. But it creates custom picker view.
items =[[NSArray alloc]initWithObjects:#"Hindi",#"English",nil];
pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(10,250,350,350)];
pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
pickerView.backgroundColor = [UIColor clearColor];
[pickerView selectRow:1 inComponent:0 animated:YES];
[self.view addSubview:view];
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
return [items count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[items objectAtIndex:row];
}
I have the following view hierarchy
UITabBarController
- UINavigationController
- UITableViewController
When the table view appears (animated) I create a toolbar and add it as subview of the TabBar at the bottom of the page
and let it animate in with the table view. Same procedure in other direction, when the table view disappears.
It does not work as expected.
The animation duration is OK, but somehow not exact the same as the animation of the table view when it becomes visible
When I display the table view for the second time, the toolbar does not disappear at all and remains at the bottom of the
parent view.
What's wrong with it?
- (void)animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[toolBar removeFromSuperview];
}
- (void)viewWillAppear:(BOOL)animated
{
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 44, 0);
[[self tableView] setContentInset:insets];
[[self tableView] setScrollIndicatorInsets:insets];
// Toolbar initially placed outside of the visible frame (x=320)
UIView *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(320, 480-44, 320, 44)];
[toolBar setTag:1000];
[[[self tabBarController] view] addSubview:toolBar];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[toolBar setFrame:CGRectMake(0, 480-44, 320, 44)];
[UIView commitAnimations];
[toolBar release];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDidStopSelector:#selector(animationDone:finished:context:)];
[toolBar setFrame:CGRectMake(320, 480-44, 320, 44)];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
Have you tried just using the table view controller's toolbarItems property? UINavigationController will manage a toolbar for you, updating it with the toolbar items of its current topmost view controller; use the -setToolbarHidden:animated: method in your -viewWillAppear: and -viewWillDisappear: to control the visibility of that toolbar.
I have a table view that has embedded UITextFields for entering some data. It also has two other fields that popup a UIPickerView and a UIDatePicker - as demonstrated in the DateCell example from Apple.
Mostly it works but I can't figure out how to cleanly transition from the text field keyboard to the other pickers - one slides out, one slides in - it looks weird and the scroll position on the table view sometimes gets screwed up - with everything scrolled off the top.
What I'd like to do is replace the text field keyboard without it animating away and without it growing the table view back to full size.
Any clues?
First, here is a screencapture showing how this looks.
Implement UITextFieldDelegate and display a "popup" containing a UIPickerView.
- (void)textFieldDidEndEditing:(UITextField *)textField {
UIPickerView *picker = [[UIPickerView alloc]
initWithFrame:CGRectMake(0, 244, 320, 270)];
picker.delegate = self;
picker.dataSource = self;
[self.view addSubview:picker];
[picker release];
}
When the keyboard disappears, a picker view is then visible.
If you want to take this a bit further, you can animate the UIPickerView "slide in" like the keyboard.
- (void)viewDidLoad {
//picker exists in the view, but is outside visible range
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480, 320, 270)];
picker.delegate = self;
picker.dataSource = self;
[self.view addSubview:picker];
[picker release];
}
//animate the picker into view
- (void)textFieldDidEndEditing:(UITextField *)textField {
[UIView beginAnimations:#"picker" context:nil];
[UIView setAnimationDuration:0.5];
picker.transform = CGAffineTransformMakeTranslation(0,-236);
[UIView commitAnimations];
}
//animate the picker out of view
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:#"picker" context:nil];
[UIView setAnimationDuration:0.5];
picker.transform = CGAffineTransformMakeTranslation(0,236);
[UIView commitAnimations];
}
//just hide the keyboard in this example
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
Just set the UITextField's inputView property to a UIPickerView.