Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling a method when a menuitem is tapped? #122

Open
mradlmaier opened this issue Jun 11, 2014 · 3 comments
Open

calling a method when a menuitem is tapped? #122

mradlmaier opened this issue Jun 11, 2014 · 3 comments

Comments

@mradlmaier
Copy link

I have a logout method which I want to call when a menuitem "Logout" is tapped to perform the logout. I am using storyboards.
Is this possible?
If yes, what code should such a method contain?

@stefanoa
Copy link
Owner

Hi mradlmaier,
to add a logout item I normally set the SASlideMenuViewController table to use a dynamic prototype and I add something like:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 5) {
        //LOGOUT
        NSString* logout = NSLocalizedString(@"Log Out", @"Log Out");
        NSString* cancel = NSLocalizedString(@"Cancel", @"Cancel");
        UIActionSheet *actionSheet =
        [[UIActionSheet alloc] initWithTitle:nil
                                    delegate:self cancelButtonTitle:cancel destructiveButtonTitle:logout
                           otherButtonTitles: nil];

        actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
        [actionSheet showInView:self.view];

    }else{
        [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
}

@mradlmaier
Copy link
Author

But that would mean, that I have to change the whole thing to use dynamic prototype cells?

Is there no way to do this with static cells?
Best regards,
Michael
On 12 Jun 2014, at 12:28, stefanoa notifications@github.com wrote:

Hi mradlmaier,
to add a logout item I normally set the SASlideMenuViewController table to use a dynamic prototype and I add something like:

-(void) tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0 && indexPath.row == 5) {
//LOGOUT
NSString
logout = NSLocalizedString(@"Log Out", @"Log Out");
NSString* cancel = NSLocalizedString(@"Cancel", @"Cancel");
UIActionSheet *actionSheet =
[[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:cancel destructiveButtonTitle:logout
otherButtonTitles: nil];

    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];

}else{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
}

}

Reply to this email directly or view it on GitHub.

@stefanoa
Copy link
Owner

You can try to link the Log Out cell to a specific segue and implement the LogOut process in a different view controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants