Add gestures to UISearchResults UITableView - uitableview

Currently my app has gestures, if you hold down on a UITableView cell you edit the object in the cell, if you tap the cell you view the object in the cell. That part works just fine but when the user uses the UISearchBar the results table does not have the same gestures.
Should I be adding the same gestures into else section of the initWithNibName?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"AutoNotes2", #"AutoNotes2");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
else {
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Concrete.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
self.searchDisplayController.searchResultsTableView.backgroundView = tempImageView;
}
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap)];
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
// Two finger, double tap
UITapGestureRecognizer *twoFingerDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTwoFingerDoubleTap:)];
twoFingerDoubleTap.numberOfTapsRequired = 1;
twoFingerDoubleTap.numberOfTouchesRequired = 2;
[self.tableView addGestureRecognizer:twoFingerDoubleTap];
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0; //seconds
//lpgr.delegate = self;
[self.tableView addGestureRecognizer:lpgr];
}

Related

UI code works but change to XIB failed

the code below works
#interface MyUICollectionViewCell : UICollectionViewCell {
}
#implementation UICollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self = [super initWithFrame:frame];
if (self) {
_moreView = [[UIView alloc] init];
_moreView.backgroundColor = [UIColor clearColor];
_moreView.frame = CGRectMake(self.frame.size.width - 70, 0, 45, 37);
[self addSubview:_moreView];
_moreView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapMoreView = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(goToDoSomething)];
[_moreView addGestureRecognizer:tapMoreView];
}
return self;
}
return self;
}
- (void)doSomeThing
{
}
when I touch the subview (gray block), it will trigger the event,
but I change to XIB(the sub view links to IBOutlet mUIView), and change the code as below, goToDoSomething cannot be triggered.
Your comment welcome
#interface MyUICollectionViewCell : UICollectionViewCell {
IBOutlet UIView *mUIView;
}
#implementation UICollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self = [super initWithFrame:frame];
if (self) {
NSArray *nibView = [[NSBundle mainBundle] loadNibNamed:#"MyUICollectionViewCell"owner:self options:nil];
UIView *bw = [nibView objectAtIndex:0] ;
bw.userInteractionEnabled = YES;
[self.contentView addSubview:bw];
mUIView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapMoreView = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(goToDoSomething)];
[mUIView addGestureRecognizer:tapMoreView];
}
return self;
}
return self;
}
- (void)doSomeThing
{
}

Swipe Gesture Recognizer PFImageView

What am I doing wrong?
The NSLog does return the action of Swipes but the image does not change.. I tried everything I know. Help Please?
I am working with Parse.com and I have a PFQueryTableView that segues a cell to a DetailView Controller. That Detail view has a PFImageView and I need it to swipe to different Images called from the Parse Data Browser (same class).
This is my .m code:
#import "BellezaDetailViewController.h"
#import "BellezaView.h"
#interface BellezaDetailViewController ()
#end
#implementation BellezaDetailViewController
#synthesize lookPhoto, bellezaView, activityIndicator;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(#"Left Swipe");
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(#"Right Swipe");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];{
[activityIndicator startAnimating];
[activityIndicator performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:10];
NSLog(#"Downloading Look");
self.lookPhoto.file = bellezaView.imagenDos;
[lookPhoto loadInBackground];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the swipe gesture on image view
[lookPhoto addGestureRecognizer:swipeLeft];
[lookPhoto addGestureRecognizer:swipeRight];
}
}
- (void)swipeRecognized:(UISwipeGestureRecognizer *)swipe{
if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){
self.lookPhoto.file = bellezaView.imagenTienda;
[lookPhoto loadInBackground];
}
if(swipe.direction == UISwipeGestureRecognizerDirectionRight){
self.lookPhoto.file = bellezaView.imagenTienda;
[lookPhoto loadInBackground];
}
}
- (void)viewDidUnload {
[self setLookPhoto:nil];
[super viewDidUnload];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
For anyone who needs help on the same thing.. this was my error:
The action and the handler should have matched: (now it works fine)
UISwipeGestureRecognizer swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(**handleSwipe**:)];
- (void)**swipeRecognized**:(UISwipeGestureRecognizer *)swipe{ if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){ self.lookPhoto.file = bellezaView.imagenTienda; [lookPhoto loadInBackground]; }
What's in between *... * should have matched.

Custom TableViewCell With Image Disappearing When Selected

I have created a custom tableviewcell class and the cells load perfectly, however, when I click on them they disappear and come back when I click on a different cell. Can anyone help me understand why? Thanks in advance!
#import "CustomTableViewCell.h"
#implementation CustomTableViewCell
UIView *backgroundView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
UIView *visibleBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(29, 0, backgroundView.bounds.size.width -58, backgroundView.bounds.size.height)];
[visibleBackgroundView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"tableViewCell.png"]]];
[backgroundView addSubview:visibleBackgroundView];
self.backgroundView = backgroundView;
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if (selected) {
UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
UIView *visibleSelectedBackground = [[UIView alloc] initWithFrame:CGRectMake(29, 0, backgroundView.bounds.size.width -58, backgroundView.bounds.size.height)];
[visibleSelectedBackground setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"selectedTableViewCell#2x.png"]]];
[selectedBackgroundView addSubview:visibleSelectedBackground];
self.selectedBackgroundView = selectedBackgroundView;
}
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
[self setHighlighted:NO];
}
}
I was able to fix it with the following solution
#import "CustomTableViewCell.h"
#implementation CustomTableViewCell{
UIView *backgroundView;
UIView *visibleBackgroundView;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
visibleBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(29, 0, backgroundView.bounds.size.width -58, backgroundView.bounds.size.height)];
[visibleBackgroundView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"tableViewCell.png"]]];
[backgroundView addSubview:visibleBackgroundView];
self.backgroundView = backgroundView;
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if (selected) {
}
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
[visibleBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"selectedTableViewCell.png"]]];
} else{
[visibleBackgroundView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"tableViewCell.png"]]];
}
}

Login page with a small list

i have just started learning objective C. want to create a small app where a login page should be there and password should be accepted only if its length is more than or equal to 8. once you submit that the next page should be a list of movies and in that page there should be a search button as well as add and remove buttons which can make that list editable. i created the login page and i have directly linked the submit button with the movie list page coz i was confused about how the condition of password length and username thing should be validated. kindly help me in doing that and to get the proper editing buttons for my movie list page.
Thanks
"ViewController.m"
#import "ViewController.h"
#import "MovieList.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)loadView{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor cyanColor];
UILabel *name=[[UILabel alloc] init];
UILabel *pass=[[UILabel alloc] init];
UITextField *username = [[UITextField alloc]init];
UITextField *password = [[UITextField alloc]init];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[name setBackgroundColor:[UIColor cyanColor]];
[name setText:#"UserID"];
[name setTextColor:[UIColor blackColor]];
[pass setBackgroundColor:[UIColor cyanColor]];
[pass setText:#"Password"];
[pass setTextColor:[UIColor blackColor]];
[button setTitle:#"SUBMIT" forState:UIControlStateNormal];
username.delegate = self;
password.delegate = self;
username.borderStyle = UITextBorderStyleRoundedRect;
password.borderStyle = UITextBorderStyleRoundedRect;
name.frame = CGRectMake(20, 15, 80, 20);
pass.frame = CGRectMake(15, 55, 80, 20);
username.frame = CGRectMake(100, 10, 200, 30);
password.frame = CGRectMake(100, 50, 200, 30);
button.frame = CGRectMake(130, 90, 80, 30);
[self.view addSubview:button];
[self.view addSubview:username];
[self.view addSubview:password];
[self.view addSubview:name];
[self.view addSubview:pass];
[button addTarget:self action:#selector(gotosecondpage) forControlEvents:UIControlEventTouchUpInside];
}
-(void)gotosecondpage
{
Movielist *secondViewcont = [[Movielist alloc] init];
[self.navigationController pushViewController:secondViewcont animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return YES;
}
- (BOOL)textFieldShouldClear:(UITextField *)textField{
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
#end
"MovieList.m"
#import "MovieList.h"
#interface Movielist()
#end
#implementation Movielist
-(void)loadView{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor cyanColor];
}
-(id)init{
[self.navigationItem setTitle:#"Movie List"];
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self.view setBackgroundColor:[UIColor cyanColor]];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = self.view.frame;
UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.backgroundColor = [UIColor cyanColor];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
[tableView setScrollEnabled:YES];
[tableView setUserInteractionEnabled:YES];
[tableView setRowHeight:35];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cellIDent"];
char ch = 'a' + indexPath.row;
cell.textLabel.text = [NSString stringWithFormat:#"%c" , ch];
return cell;
}
#end
Checking length is very straight. The important thing is how do you navigate from login page. Currently I see gotosecondpage function is responsible. You can probably write a validateParams method, under which you can call gotosecondpage if all conditions are met.
This code will tell you about password length:
-(void) validateParams
{
NSString * password = [password text];
if ([password length] < 8) //and maybe other conditions, too
{
[self gotosecondpage];
}
else
{
//report error - maybe show some UILabel near username / password fields to show which one of them went wrong
}
}
Note that there are many other things you can do - like telling the user which field needs correction, and there are many better ways. Since your requirements are quite basic, above should help for now.

Display a custom background picture in UISearchResultsTableView in iOS

Currently I have this code that changes the default background in a TableView to a custom picture, but when the user does a search in the UISearchBar, the Search Results TableView is a plain white background. Where/how do I change it to be the same as my regular non-searched TableView?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Employee List", #"Employee List");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
else {
{
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Cloth.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
}
}
}
return self;
}
You should be able to access the searchResults TableView through the searchDisplay Controller:
...
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Cloth.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
self.searchDisplayController.searchResultsTableView.backgroundView = tempImageView;
...

Resources