Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JJS123

macrumors newbie
Original poster
Nov 1, 2008
2
0
Hello everyone:
I'm sure someone has come across this at one time or another and hopefully can help.

I have a UITableView for which I have created a custom view for each row. The custom view is created in another class (which implements a UIView) which includes two images, a label, and a detaildisclosurebutton.

The view displays just fine, the problem I have run into comes in when the user pushes the detaildisclosurebutton. The program should push another view controller onto the view controller stack then display it.

I'm having a hard time trying to do this because since the button is created in the seperate view class, the button push is also handled there and I either cannot push the new view controller onto the view controller stack (because it implements a UIView and not a UIViewController) or there's some way of doing it that I'm not aware of. It would seem that no matter what you do, you need a reference to the rootviewcontroller which seems like it would end up being a cyclical reference.

Should I add a reference to the rootviewcontroller in the custom UIView class and push it that way? (which seems a little messy) Or is there a better way of doing something like this? I can see that this issue can come up in the future and I would like to get the accepted method for doing this.

Thanks,
Joe
 

lawicko

macrumors member
Jul 17, 2008
44
0
There is a class called UITableViewCell, which is exactly what you need. Make your custom view for each row inherit from UITableViewCell and you should get notification whenever user taps on the row. The best way to evaluate this is to implement UITableViewDelegate method:
– tableView:didSelectRowAtIndexPath:
I hope this helps.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
If you have a tableview then you have a view controller that controls it. All the code for navigation to new views should be in that view controller. It should have a didSelectRowAtIndexPath, which is called when a row is touched. If there's some other control in your cells that get touched they should send their action method to this view controller.

The next view that gets pushed should have its own view controller.
 

JJS123

macrumors newbie
Original poster
Nov 1, 2008
2
0
PhoneyDeveloper:

So then if someone pushes a button in that view, I should be able to respond to that event in my UIView class, and pass the event along to the next level up the chain of responders? I think that would probably be the table row itself (didSelectRowAtIndexPath I guess)

If that's what you're saying, then that's something I need to do a little research on.

If I can pass the event to the table row, then I have to figure out what was touched in the tablerow. But at least this would put me back into the roowviewcontroller class which is where I need to be to push the new view controller.

I'm still green enough that I do not yet understand how to find out what was touched or pushed in the view, nor am I familliar with sending the event up the chain of responders, but I'm sure Apple has something with regard to that.

Thanks,
Joe
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.