0

Here is what I already have;

  • I have loaded a Custom cell from XIB file (UITableViewCell)
  • This custom cell contains Button A and B
  • Created a IBAction to handle Button A
  • loaded above XIB file in MyTableView class (UIViewController)

Now I want to load another view(Most probably a XIB file) on Button A clicked event, in IBAction function I have tried this;

    // Where MyTableView is a class which loads this custom cell
    // ModalView is a name of XIB File
    MyTableView *vc = [[MyTableView alloc] initWithNibName:@"ModalView" bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];

but it throughs error at "self.navigationController", says Property navigationController not found on object of type MyTableViewCell class, i know this is happening due to the UITableViewCell class and the self in this line is referring to the UIViewController Object and I should use awakeFromNib or something like that, but I couldn't find any sufficient example to let me achieve what I need.

Faisal Ameer
  • 416
  • 5
  • 13
  • tred this as well; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ModalView" owner:self options:nil];    UIView *nView = [nib objectAtIndex:0]; but self doesn't support navigationcontroller or pushview etc, dont know how to embed view on top as a Modal View??? – Faisal Ameer May 23 '12 at 07:05

1 Answers1

1

ok, I have solved my problem;

In cellForRowAtIndexPath function, where I was fetching the XIB file (UITableViewCell) to represent a custom designed cell, I created a button and assign it the button from the XIB view and then attached the IBAction to it;

    // SimpleTableCell is the XIB filename (UITableViewCell)
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];


    UIButton *btn = [[UIButton alloc] init];
    btn = cell.btn;
    [btn addTarget:self action:@selector(smsBtnClicked:) 
                            forControlEvents:UIControlEventTouchUpInside];
Faisal Ameer
  • 416
  • 5
  • 13
  • and off course in this IBAction event UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; [viewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; [self presentViewController:viewController animated:YES completion:NULL]; – Faisal Ameer May 23 '12 at 22:49