开发者

i have a table view in root view class, i want to display a modal view when the user clicks the cell

My table views data source and delegate is set to another class (tableModule). Now i wrote the following code to show the modal view:

    NewRule *newRuleModalView = [[NewRule alloc] init]; 
newRuleModalView.modalPresentationStyle = UIModalPresentationFullScreen;
开发者_Python百科newRuleModalView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:newRuleModalView animated:YES];
newRuleModalView.view.superview.frame = CGRectMake(0, 0, 750, 1004);
[newRuleModalView release];

This code is not working for me. Then i set the tableview datasource and delegate to self. Then the same code worked for me. How can i use it in the first situation? please help me, i'm a fresher to this field.


If your tableModule class is not a view controller, and (I think) is not the currently visible view controller, then you can't call presentModalViewController: on it. If you've put this code in didSelectRowAtIndexPath: in your view controller, and the view controller is not the delegate of the table view, it will never get called.

If you want to keep a separate object as your table view's delegate and data source, your table view's delegate (tableModule) needs to have a pointer to your view controller, so it can tell the view controller to present the modal view.

Could you possibly have the datasource as tableModule and the delegate as your view controller, or do you need information from tableModule to implement the delegate methods?

From your comments, you'd need the following:

  • Create a property on tableModule, of your rootViewController type
  • When creating tableModule, set tableModule.rootViewController = self
  • In your did select row method, instead of [self presentModal..., do [self.rootViewController presentModal...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜