0

I have got an UITableViewCell and I want to call a void in a ViewController of the UITabBar in it. Is that possible using [UIApplication sharedApplication]? If yes, how can I do that?

Thanks in advance.

user1710004
  • 209
  • 1
  • 4
  • 12

1 Answers1

1

This is pretty vague, the answer is yes, it is possible to do such a thing. You just need to design your classes in such a way to make it possible.

A number of ways to approach it

  1. Create a method on ViewController's interface that UITableViewCell can call
  2. Use the delegate pattern
  3. Post a notification and observer the notification in ViewController

With that said, this sounds weird to me, why would your UITableViewCell act on a UITabBar? The interaction "feels" strange. Usually touching a cell in a table does not change the tab that the user is on, it could be fairly confusing. If that is not what you're doing, then why is this method in the ViewController that controls the UITabBar? You may need to separate your concerns.

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
  • Thanks for your answer! The point is that I do not want to change the Tab. It will just call a void of an UITabBars tabs ViewController! – user1710004 Feb 07 '13 at 17:41
  • What does that void method do? – Chris Wagner Feb 07 '13 at 18:34
  • It adds a String to an Array and reloads the included TableView, which will cause starting an async download. – user1710004 Feb 07 '13 at 18:42
  • Sounds like a method that is a separate concern from the UITabBar's class. I'd abstract the method into a different class that you can call in a more sensible. – Chris Wagner Feb 07 '13 at 22:29
  • Well, I now found a way doing it using a custom [UIApplication sharedApplication].delegate! I think I used to many subclasses. Thanks anyway! – user1710004 Feb 24 '13 at 15:02