Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
UIKit setAccessoryType for TableView — Gideros Forum

UIKit setAccessoryType for TableView

scurvyratscurvyrat Member
edited September 2012 in Plugins
I've been using the uikit.mm in my app and am finding that it would be great if the accessory indicators could be added to table rows. It appears that it can be set for the table, and then all rows get the same accessory indicator. It can also be set row by row, but I'm not sure how that would get implemented in the current data table.

Does anyone have a suggestion on what is the best solution for at least having each row have the same accessory?

Comments

  • So I figured it out, I was trying to set the accessory type to the view instead of the cell.

    I added the following:
     
    // Add to the public section of the TableView class
     
        void setAccessoryType(NSString *accessoryType)
        {
            if ([accessoryType isEqualToString:<a href="http://forum.giderosmobile.com/profile/None" rel="nofollow">@None</a>]) {
                delegate.accessoryType = UITableViewCellAccessoryNone;
            }else if([accessoryType isEqualToString:<a href="http://forum.giderosmobile.com/profile/DisclosureIndicator" rel="nofollow">@DisclosureIndicator</a>]){
                delegate.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }else if([accessoryType isEqualToString:<a href="http://forum.giderosmobile.com/profile/DetailDisclosureButton" rel="nofollow">@DetailDisclosureButton</a>]){
                delegate.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
            }else if([accessoryType isEqualToString:<a href="http://forum.giderosmobile.com/profile/Checkmark" rel="nofollow">@Checkmark</a>]){
                delegate.accessoryType = UITableViewCellAccessoryCheckmark;
            }else{
                delegate.accessoryType = UITableViewCellAccessoryNone;
            }
        }
    there are a few other bits you have to add like:
    <a href="http://forum.giderosmobile.com/profile/property" rel="nofollow">@property</a> (nonatomic, assign) UITableViewCellAccessoryType accessoryType;
    <a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> accessoryType;
    at the beginning of the TableView section

    and then in the cellForRowAtIndexPath function add below the textlabel stuff:
    // Accessory Type
    cell.accessoryType = accessoryType;
    you also have to add in the delegate a method to send when they click on the Accessory Detail Disclosure Button. I don't believe the normal Disclosure Indicator sends a message.

    so add in:
    //delegate methods
    -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
    {
    	getObject(L, target);
    	if (!lua_isnil(L, -1))
    	{
    		lua_getfield(L, -1, "dispatchEvent");
    		lua_pushvalue(L, -2);
    		lua_getglobal(L, "Event");
    		lua_getfield(L, -1, "new");
    		lua_remove(L, -2);
    		lua_pushstring(L, "accessoryButtonTappedForRowWithIndexPath");
    		lua_call(L, 1, 1);
     
            lua_pushinteger(L, indexPath.row);
            lua_setfield(L, -2, "Row");
    		if (lua_pcall(L, 2, 0, 0) != 0)
    		{
    			g_error(L, lua_tostring(L, -1));
    			return;
    		}
    	}
    	lua_pop(L, 1);
        return;
    }
    Here is with the DisclosureIndicator

    image

    And with the DetailDisclosureButton

    image

    In your cellForRowAtIndexPath function just put in:
    TableView:setAccessoryType("DetailDisclosureButton")

    and you should be set.

    Enjoy!
    iOS Simulator Screen shot Sep 11, 2012 2.46.48 PM.png
    320 x 480 - 90K
    iOS Simulator Screen shot Sep 11, 2012 2.46.46 PM.png
    320 x 480 - 70K
  • techdojotechdojo Guru
    Accepted Answer
    Great info - thanks for sharing :)
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Sign In or Register to comment.