From: Panayotis K. <pan...@pa...> - 2011-05-10 17:03:44
|
There is also one more thing. I believe, if an optional method returns nothing, or the default value is already known, there is no reason to use the "respondsToSelector" method. In the case of the known & documented default value, create a regular method which simply returns this value (like for example "editingStyleForRowAtIndexPath") In the case which does not return anything, just create an empty method. (like for example "heightForRowAtIndexPath"). The problem is exactly with methods like "heightForRowAtIndexPath", where the default value is not known at all, and SHOULD return something. *Then* it is required to do the respondsToSelector trick On May 7, 2011, at 9:54 AM, Arno Puder wrote: > > you got the gist of it. Two things: > > 1. In your boolean expression, you don't have to go through the TIB > to retrieve the function pointer. You can inline the function > directly as a constant. > 2. It may be possible that the XMLVM_VTABLE_xxx symbol isn't defined. > This can happen if the method is not overridden. XMLVM performs > compile-time optimizations and will not even generate a vtable > entry for that method. In this case, the result should always > be FALSE. > > Here a re-worked version: > > if (aSelector == @selector(tableView:heightForRowAtIndexPath:)) { > #ifdef > XMLVM_VTABLE_IDX_org_xmlvm_iphone_UITableViewDelegate_heightForRowAtIndexPath___ > VTABLE_PTR f = ((org_xmlvm_iphone_UITableViewDelegate*) > delegate_)->tib-> > vtable[XMLVM_VTABLE_IDX_org_xmlvm_iphone_UITableViewDelegate_heightForRowAtIndexPath___org_xmlvm_iphone_UITableView_org_xmlvm_iphone_NSIndexPath]; > return f != (VTABLE_PTR) > org_xmlvm_iphone_UITableViewDelegate_heightForRowAtIndexPath___org_xmlvm_iphone_UITableView_org_xmlvm_iphone_NSIndexPath; > #else > return 0; > #endif > > If the mailer messes up the indentation and you can't read it, I'll send > it as an attachment. > > Arno > > > > On 5/6/11 2:50 AM, Markus Heberling wrote: >> Hi, >> >> I have manually implemented optional method handling for 2 Methods from UITableViewDelegate. >> >> http://xmlvm-reviews.appspot.com/121001/ >> >> If you think that it is ok that way I would implement the other methods, too. >> >> Markus |