iPad search display controller displaying results starting in second cell - ios

I added a Searchbar and Search Display Controller to my iPad app that use localSearch. I believe I implemented the delegates correctly. The search works fine and displays the results but the issues is that these results start in the second cell. The first cell in the popup display being empty. I double checked to see if the map items count and contents were correct and they were.
The code:
- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
if (![self connected]) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Cannot Connect",nil)
message:NSLocalizedString(#"Please make sure you are connected to the internet and try again.",nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",nil) otherButtonTitles:nil] show];
}
else if ([mainToolbar isHidden])
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Search Unavailable",nil)
message:NSLocalizedString(#"Please make sure you aren't drawing an AOI or using a tool and then try again.",nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",nil) otherButtonTitles:nil] show];
}
else {
// Cancel any previous searches.
[localSearch cancel];
// Perform a new search.
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = self.searchBar.text;
request.region = self.mapView.region;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler: ^(MKLocalSearchResponse *response, NSError *error){
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([response.mapItems count] == 0)
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"No Results",nil)
message:nil
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",nil) otherButtonTitles:nil] show];
return;
}
if (error != nil)
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Map Error",nil)
message:NSLocalizedString(#"Sorry.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",nil) otherButtonTitles:nil] show];
return;
}
results = response;
[self.searchDisplayController.searchResultsTableView reloadData];
}
];
}
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [results.mapItems count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *IDENTIFIER = #"SearchResultsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDENTIFIER];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IDENTIFIER];
}
MKMapItem *item = results.mapItems[indexPath.row];
cell.textLabel.text = item.name;
cell.detailTextLabel.text = item.placemark.addressDictionary[#"Street"];
return cell;
}
Here is a screenshot of the issue.

The first row contains the table header.

Related

Display alert if no recipients are selected iOS

I have a page where we select recipients (who are friends) to send an image to. but if no recipients are selected we can still send the message. i want it so that if no recipients are selected we can show a UIAlertView. for me its not working when i try to display an alert please see my code below.
.h
#property (nonatomic, strong) NSArray *friends;
#property (nonatomic, strong) PFRelation *friendsRelation;
#property (nonatomic, strong) NSMutableArray *recipients;
- (IBAction)send:(id)sender;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.recipients = [[NSMutableArray alloc] init];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.friendsRelation = [[PFUser currentUser] objectForKey:#"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:#"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(#"Error %# %#", error, [error userInfo]);
}
else {
self.friends = objects;
[self.tableView reloadData];
}
}];
//display camera modally etc......
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
cell.textLabel.text = user.username;
if ([self.recipients containsObject:user.objectId]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
PFUser *user = [self.friends objectAtIndex:indexPath.row];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.recipients addObject:user.objectId];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[self.recipients removeObject:user.objectId];
}
NSLog(#"%#", self.recipients);
}
here is the part where i try to display my alert
- (IBAction)send:(id)sender {
if (!self.recipients) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Select some friends" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
[self uploadMessage];
//we upload the message in method to parse.com
}
}
it does not seem to show for some reason so we can send messages to no one. how can i show the alert view?
Try this. Check objects of recipients is equal to 0 or not.
- (IBAction)send:(id)sender {
if ([self.recipients count]==0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Select some friends" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
[self uploadMessage];
//we upload the message in method to parse.com
[self.tabBarController setSelectedIndex:1];
}
}
The problem with your code is the condition that you are checking::
if (!self.recipients)
here self.recipients will always give true value as it will look for memory address of this object, which you have assigned to it in your viewDidLoad method.
You have to check for the count of the array in your scenario.

UITableViewCell staying empty

I am trying to fill a UITableView with the objects of an NSMutableArray which is filled from a table in Parse. The array is definitely being filled (I checked its contents with an NSLog), but the table is staying empty. I have tried A LOT of different ways including the following:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
PFObject *postsObject = [postsArray objectAtIndex:indexPath.row];
cell.textLabel.text = [postsObject objectForKey:#"message"];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
if (!cell) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (tableView == table) {
cell.textLabel.text = [postsArray objectAtIndex:indexPath.row];
}
return cell;
}
and the much simpler
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = [table dequeueReusableCellWithIdentifier:#"Cell"];
cell.messageLabel.text = [NSString stringWithFormat:[postsArray objectAtIndex:[indexPath row]]];
return cell;
}
Does anyone have any ideas?
Thanks in advance :)
EDIT:
My dataSource methods are:
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return postsArray.count;
}
EDIT #2:
My code I'm using to fill my array and reload my tableView
PFQuery *findData = [PFQuery queryWithClassName:#"AllPosts"];
[findData setLimit:1000];
[findData findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error == nil) {
for (PFObject *object in objects) {
PFObject *post = object[#"content"];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:post, nil];
postsArray = array;
[table reloadData];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Unable To Load" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
You are doing it wrong , you are replacing the array with new data whenever you are finding a PFObject in objects, your code should be like this:-
//first alloc your array
postsArray=[[NSMutableArray alloc] init];
//Logic goes here
PFQuery *findData = [PFQuery queryWithClassName:#"AllPosts"];
[findData setLimit:1000];
[findData findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error == nil) {
for (PFObject *object in objects) {
PFObject *post = object[#"content"];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:post, nil];
[postsArray addObject:array];
[table reloadData];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Unable To Load" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
You also need to check if the cell object is actually returned. Also put in the following code after the call to dequeueReusableCellWithIdentifier:
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
}
This would solve your problem

Tableview display alert error

I am writing a simple tableview app, when tapping the row, a alert shows up.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *rowValue =self.greekLetters[indexPath.row];
// NSString *message=[[NSString alloc] initWithFormat:#"You selected%#!",rowValue];
if (indexPath.row==0) {
NSString *message=[[NSString alloc] initWithFormat:#"This is course aaaaa",rowValue];
}
if (indexPath.row==1) {
NSString *message=[[NSString alloc] initWithFormat:#"This is course aaaaa"];
}
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Course introduction" message:message delegate:nil cancelButtonTitle:#"Return to courses list" otherButtonTitles:nil, nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
However, Xcode doesn't like my if statement here, while the following statement works.
NSString *message=[[NSString alloc] initWithFormat:#"You selected%#!",rowValue];
Could anyone give me an example of how to use the message here please?
This is a problem with scope. You need to declare message before the if statement:
NSString *message;
if (indexPath.row==0) {
message=[[NSString alloc] initWithFormat:#"This is course aaaaa",rowValue];
}
else if (indexPath.row==1) {
message=[[NSString alloc] initWithFormat:#"This is course aaaaa"];
}
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Course introduction" message:message delegate:nil cancelButtonTitle:#"Return to courses list" otherButtonTitles:nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
However, if the course number is determined by the row number do:
NSString *rowValue =self.greekLetters[indexPath.row];
NSString *message = [[NSString alloc] initWithFormat:#"This is course %#",rowValue];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Course introduction" message:message delegate:nil cancelButtonTitle:#"Return to courses list" otherButtonTitles:nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
You've forgotten to include %# in the first if-statement.
NSString *message= [[NSString alloc] initWithFormat:#"This is course aaaaa %#",rowValue];
By the way, there's no need to do [[NSString alloc] init] at all, just use [NSString stringWithFormat:...]

Not Able to show UIAlert on Exception

I am using UITableView. And if there is no network connection then there will be exception thrown in viewDidload. My viewDidLoad function is:
#try {
NSLog(#"Request URL = %#",URLString);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:URLString]];
NSData *response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSDictionary *tableData = [NSJSONSerialization JSONObjectWithData:response
options:0
error:&jsonParsingError];
// Grab whole data with data field in JSON
// responseArray = [tableData objectForKey:#"data"];
responseArray = [[NSMutableArray alloc]initWithArray:[tableData objectForKey:#"data"]];
for(int i = 0; i < responseArray.count; i++)
{
NSArray * tempArray = responseArray[i];
responseArray[i] = [tempArray mutableCopy];
}
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(280.0, 0.0, 40.0, 40.0)];
[btn setImage:[UIImage imageNamed:#"sort_icon.png"] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(showActionSheet) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barbutton = [[UIBarButtonItem alloc]initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = barbutton;
}
#catch (NSException *exception)
{
exceptionOccured = YES;
NSLog(#"Exception Ocurred");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error in connectivity" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
In cellForRowAtIndexPath I am doing this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#try {
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
tempDict = [responseArray objectAtIndex:indexPath.row];
return cell;
}
#catch (NSException *exception)
{
NSLog(#"Error in CEll Create");
NSLog(#"Draw Alert");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error in connectivity" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
and in AlertViewDelegate Function I am doing
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self.navigationController popViewControllerAnimated:YES];
}
Now problem is that it is not showing the Alert whenever there is an exception and re-throws the exception and shows the Error
Thread 1: EXC_BAD_ACCESS(code=2, address=0x2)
Any help will be appreciated...
You should avoid throwing exceptions in your code.
First of all you could use Reachability Class to determine whether or not an active internet connection is available.
I would definitively recommend using the NSURLConnectionDelegate protocol for URL connections. So you can use the better asynchronous programming style.
The problem is somewhere else. When - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is called it means the system needs the tableView to be reloaded. Therefore, you should not check for data inside that function. When you enter this function, you should be sure that your data is ok.
What you have to do is firstly check your data in a specific function:
-(void)CheckData(NSArray *responseArray) {
#try {
//Retrieve your data & check if its valid
self.dataArray = responseArray;
[self.tableView reloadData];
}
#catch (NSException *exception)
{
NSLog(#"Error in check Data");
NSLog(#"Draw Alert");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error in connectivity" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Then, implement your data source delegates:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.dataArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier] autorelease] ;
}
//TODO: Init your cell using your self.dataArray content
return cell;
}
I would recommend import this SystemConfiguration framework and use the same. This will check whether network connection is available or not. Below is the simple code:-
#import <SystemConfiguration/SystemConfiguration.h>
-(void)yourMethod
{
SCNetworkConnectionFlags flags = 0;
if (yourhostname && [yourhostname length] > 0)
{
flags = 0;
BOOL found = NO;
SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [yourhostname UTF8String]);
if (reachabilityRef)
{
found = SCNetworkReachabilityGetFlags(reachabilityRef, &flags)
&& (flags & kSCNetworkFlagsReachable)
&& !(flags & kSCNetworkFlagsConnectionRequired);
CFRelease(reachabilityRef);
reachabilityRef = NULL;
}
if (found)
{
NSLog(#"Connection available");
}
else
{
NSLog(#"Connection not available");
}
}

panning cells with custom action in ios

Hi i am trying to make a tableview with mailbox style panning http://www.mailboxapp.com/ for that i am using this library https://github.com/gloubibou/HHPanningTableViewCell and it is working fine, i swipe the cell and it moves just fine, the problem is that i want to trigger a custom action when i swipe the cell and i have only been able to do it when it is open and then i touch it.
This is the code where the action is happening
#import "TableViewController.h"
#import "HHPanningTableViewCell.h"
#interface TableViewController ()
#property (nonatomic, retain) NSArray *rowTitles;
#end
#implementation TableViewController
#pragma mark -
#pragma mark Initialization
- (id)init
{
self = [super initWithNibName:#"TableViewController" bundle:nil];
if (self != nil) {
self.rowTitles = [NSArray arrayWithObjects:#"Pan direction: None", #"Pan direction: Right", #"Pan direction: Left", #"Pan direction: Both", #"Custom trigger", nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
#pragma mark -
#pragma mark Accessors
#synthesize rowTitles = _rowTitles;
#pragma mark -
#pragma mark Rotation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.rowTitles count] * 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSInteger directionMask = indexPath.row % 5;
if (cell == nil) {
cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];
// dark_dotted.png obtained from http://subtlepatterns.com/dark-dot/
// Made by Tsvetelin Nikolov http://dribbble.com/bscsystem
drawerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"dark_dotted"]];
cell.drawerView = drawerView;
}
if (directionMask < 3) {
cell.directionMask = directionMask;
}
else {
cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;
if (directionMask == 4) {
cell.delegate = self;
}
}
cell.textLabel.text = [self.rowTitles objectAtIndex:directionMask];
return cell;
}
- (void)gestureRecognizerDidPan:(UIPanGestureRecognizer*)gestureRecognizer{
}
#pragma mark -
#pragma mark Table view delegate
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSInteger directionMask = indexPath.row;
NSString *celda = [NSString stringWithFormat:#"%d", directionMask];
[cell isKindOfClass:[HHPanningTableViewCell class]];
HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;
if (directionMask == 1) {
if (HHPanningTableViewCellDirectionRight) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"1"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
if ([panningTableViewCell isDrawerRevealed]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"1"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"2"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#pragma mark -
#pragma mark HHPanningTableViewCellDelegate
- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"You triggered a custom action"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
#end
I know i could use a Gesture recognizer to trigger the action but i think the library is already doing that.
in this part i trigger an action knowing exatly the cell, where was it paned to and if the back of the cell is revealed or not, but always by clicking it since it is a select function.
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSInteger directionMask = indexPath.row;
NSString *celda = [NSString stringWithFormat:#"%d", directionMask];
[cell isKindOfClass:[HHPanningTableViewCell class]];
HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;
if (directionMask == 1) {
if (HHPanningTableViewCellDirectionRight) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"1"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
if ([panningTableViewCell isDrawerRevealed]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"1"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"2"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
return indexPath;
}
and i believe this other part is where the custom action should be trigered but the program never enters this function
- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Custom Action"
message:#"You triggered a custom action"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
I hope i made myself clear and thank you in advance.
Change the delegate method to
- (void)panningTableViewCell:(HHPanningTableViewCell *)cell didTriggerWithDirection:(HHPanningTableViewCellDirection)direction;
For the delegate method to trigger you need to set your controller as delegate for the cell. Currently in your cellForRowAtIndexPath the controller is assigned as delegate only when directionMask is 4. So you either set directionMask to be 4 in your current code (which is returning a value based on the cell position instead) or you set the controller as delegate in every case, as I've done below.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSInteger directionMask = indexPath.row % 5;
if (cell == nil) {
cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];
// dark_dotted.png obtained from http://subtlepatterns.com/dark-dot/
// Made by Tsvetelin Nikolov http://dribbble.com/bscsystem
drawerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"dark_dotted"]];
cell.drawerView = drawerView;
}
if (directionMask < 3) {
cell.directionMask = directionMask;
}
else {
cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;
// previous code
//if (directionMask == 4) {
// cell.delegate = self;
//}
}
cell.delegate = self;
cell.textLabel.text = [self.rowTitles objectAtIndex:directionMask];
return cell;
}

Resources