简体   繁体   中英

iOS: Call delegate method in view to make that view modal

I have a TabBar messaging application with two views, A and B. In view A, I declared an object of type delegate which has a delegate method in view B. Now, whenever something happens in view A, the method in the delegate object gets called, which then triggers the delegate method in view B to fire. What I want to happen whenever this "something" happens is that if it's view A that is visible, I want the tab bar to switch the view to view B. If view B is visible, nothing happens to the view. How do I make this happen?

The actual app is more complicated than the one described above because the TabBar and all its associated views are in another view controller that gets loaded in the appdelegate. (I am a contributor to this app and the original developers in their infinite wisdom decided to make things really cryptic.) And I don't want to implement the solution that uses something along the lines of ...

[self.tabBarController setSelectedIndex:1]

... because that is not how I want it to happen. I just want to make the view in B visible whenever delegate in view A is called. Thanks.

I had edited my post: This line [self.tabBarController setSelectedIndex:1] and the clauses above and underneath it make up one line. I put ellipsis points to emphasize.

If you just want to determine which view is visible you can use the -isDesendentOfView: method:

  if([viewA isDescendentOfView:someView]) {
      //viewA is visible as a subview to `someView`
 }

EDIT: Upon reading your question over. I think you want to send the sender parameter in to your delegate method to determine where it came from..i,e:

If your delegate method was defined as this:

-(void)someMethod:(id)sender;

In your delegate you would do something like this:

-(void)someMethod:(id)sender {

    UIView *aView = (UIView*)sender;

        if(aView == viewA) {

       }

        if(aView == viewB) {

       }
}  

Hope this helps, or at least put's you on the path to figuring it out !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM