ios how to show modal view on clicking uimenuitem

243 views Asked by At

I am developing an app where on click of table cell i am displaying UIMenuItem with 'Info' button. Now on clicking the info button i have to show a view and dismiss on click of cancel.

In MytableView(Custom tableView)

-(void)tableView : (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"didSelectRow");


    UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Info" action:@selector(handleInfo:)];
    [[UIMenuController sharedMenuController] setMenuItems: @[testMenuItem]];
    [[UIMenuController sharedMenuController] update];
}

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
//    if (action == @selector(handleInfo:))
//    {
//        return YES;
//    }
    return NO;
}

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    // required
}
-(IBAction)handleInfo:(id)sender{

    InfoViewController *readInfo = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
    readInfo.label.text = @"Info of table cell";

    [myAppDelegate.navController pushViewController:readInfo animated:NO];
}

I am able to push the view but unable to dismiss it and value passed to readInfo.label.text is returning null.

1

There are 1 answers

0
Siu Chung Chan On

1. readInfo.label.text is returning null. Because at this time the label in xib still not rendered. to solve this, can assign the text after pushViewController.

but i would prefer to pass the text in the initWithNib method. may be create another method initWithNibName:@"xxx" text:@"Info of table cell"; store it in InfoViewController, and assign this text to it in viewDidLoad.

2. what method did you call when dismiss that InfoViewController??

[myAppDelegate.navController popViewController] 

this should do the trick.