Okay so i decided to move my code for my UITableView delegates into another class. a subclass if you will, A subclass so that it would make it easier to access all the elements my Cellforrowwithindexpath function does within said subclass.
But now there is a slight issue…
It works fine, as far as the UItableView is concerned, But then when i tried to use the navigation controller to push a view on top, it did not work, i then discovered that self…Within my main class was actually an instance of my subclass…What? so self is not actually equal to self…
Can anyone give me any insight as to what i am doing so colossally wrong here?
EDIT: So i changed it to instead be a subclass to a delegate and it works fine, just in case anyone else runs into This issue, But i am still confused as to why it was happening in the first place…
Code:
@interface OpenGameList : MainMenuViewContoller <UITableViewDelegate,UITableViewDataSource>
{
}
@end
In my MainMenuViewController’s viewDidLoad function
_openGameList = [[OpenGameList alloc] init];
_openGameList.delegate = self;
friendsTable.delegate = _openGameList;
friendsTable.dataSource = _openGameList;
And than after that it seems that any use of self in MainMenuViewController is equal to OpenGameList hence why using [[fromView navigationController] pushViewController:toView animated:NO]; does not work
selfalways points to the object that was actually instantiated – the most derived class.When you have an instance of a subclass, and you send a message to
self, the subclass’s implementation will always be invoked if there is one. It doesn’t matter whether or not you’re in the superclass’s implementation file or the subclass’s implementation file.This is an essential for polymorphism: it’s what allows subclasses to override the behavior of a parent class. Take
-[UIView drawRect:]for example. To invoke the drawing code for subclasses, when code inUIViewinvokes[self drawRect:]it’s the subclass’s drawing implementation which needs to be called.It might help to remember that superclasses and subclasses aren’t parent and child objects, but less and more specific types which apply to the same object. A
UITableViewis also aUIScrollView,UIView, andNSObject, but when you make one, there is one object which is all of those things, andselfalways refers to that one.