Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
how to extend uikit plugin? — Gideros Forum

how to extend uikit plugin?

louislouis Member
edited May 2012 in Plugins
HI @MikeHart ,@Caroline:
I have trouble with uikit plugin,

UIKIT plugin implement a tableView, but only text can be displayed in the table, now I want to display customize the cell's format.(more columns,and display images.)

so I crate a interface class is MyTableViewCell first,
#import <UIKit/UIKit.h>
 
<a href="http://forum.giderosmobile.com/profile/interface" rel="nofollow">@interface</a> MyTableViewCell : UITableViewCell
 
<a href="http://forum.giderosmobile.com/profile/property%28nonatomic" rel="nofollow">@property(nonatomic</a>,retain) UILabel *lb_title;  
<a href="http://forum.giderosmobile.com/profile/property%28nonatomic" rel="nofollow">@property(nonatomic</a>,retain) UILabel *lb_date;  
<a href="http://forum.giderosmobile.com/profile/property" rel="nofollow">@property</a> (nonatomic,retain) UILabel *lb_points; 
 
<a href="http://forum.giderosmobile.com/profile/property%28nonatomic" rel="nofollow">@property(nonatomic</a>,retain) UILabel *lb_title_content;  
<a href="http://forum.giderosmobile.com/profile/property%28nonatomic" rel="nofollow">@property(nonatomic</a>,retain) UILabel *lb_date_content;  
<a href="http://forum.giderosmobile.com/profile/property" rel="nofollow">@property</a> (nonatomic,retain) UILabel *lb_points_content; 
 
<a href="http://forum.giderosmobile.com/profile/end" rel="nofollow">@end</a>
second,implement that:
#import "MyTableViewCell.h"
 
<a href="http://forum.giderosmobile.com/profile/implementation" rel="nofollow">@implementation</a> MyTableViewCell
 
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_title = _lb_title ;
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_date  = _lb_date ;
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_points = _lb_points ;
 
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_title_content = _lb_title_content ;
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_date_content  = _lb_date_content ;
<a href="http://forum.giderosmobile.com/profile/synthesize" rel="nofollow">@synthesize</a> lb_points_content = _lb_points_content ;
 
 
-(id) init{
    [super init];
 
    if(self){
        [self setFrame:CGRectMake(0, 0, 320, 120)];
        self.backgroundColor = [UIColor blueColor];
 
        int height = 25 ;
        int middle_height = 5 ;
 
        UIColor * bgcolor = [UIColor yellowColor];
 
        _lb_title = [[UILabel alloc] initWithFrame:CGRectMake(20, 5 + height * 0 + middle_height * 0, 45, height )];
        _lb_title.backgroundColor = bgcolor;
        _lb_title.text = <a href="http://forum.giderosmobile.com/profile/title%3A" rel="nofollow">@title:</a>;
 
        _lb_date = [[UILabel alloc] initWithFrame:CGRectMake(20, 5 + height * 1 + middle_height * 1, 45, height )];
        _lb_date.backgroundColor = bgcolor;
        _lb_date.text = <a href="http://forum.giderosmobile.com/profile/time%3A" rel="nofollow">@time:</a>;
 
        _lb_points = [[UILabel alloc] initWithFrame:CGRectMake(20, 5 + height * 2+ middle_height * 2, 45, height)];
        _lb_points.backgroundColor = bgcolor;
        _lb_points.text = <a href="http://forum.giderosmobile.com/profile/point%3A" rel="nofollow">@point:</a>;
 
        _lb_title_content = [[UILabel alloc] initWithFrame:CGRectMake(70, 5 + height * 0 + middle_height * 0, 240, height)];
        _lb_title_content.backgroundColor = bgcolor;
        _lb_title_content.text = <a href="http://forum.giderosmobile.com/profile/--------------" rel="nofollow">@--------------</a>;
 
        _lb_date_content = [[UILabel alloc] initWithFrame:CGRectMake(70, 5 + height * 1 + middle_height * 1, 240, height)];
        _lb_date_content.backgroundColor = bgcolor;
        _lb_date_content.text = <a href="http://forum.giderosmobile.com/profile/--------------" rel="nofollow">@--------------</a>;
 
        _lb_points_content = [[UILabel alloc] initWithFrame:CGRectMake(70, 5 + height * 2 + middle_height * 2, 240, height )];
        _lb_points_content.backgroundColor = bgcolor;
        _lb_points_content.text = <a href="http://forum.giderosmobile.com/profile/--------------" rel="nofollow">@--------------</a>;
 
 
 
        [self addSubview:_lb_title];
        [self addSubview:_lb_points];
        [self addSubview:_lb_date];
 
        [self addSubview:_lb_title_content];
        [self addSubview:_lb_date_content];
        [self addSubview:_lb_points_content];
    }
    return  self ;
}
third,edit uikit tableview code:
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 
 
 
    static NSString *CellIdentifier = <a href="http://forum.giderosmobile.com/profile/Cell" rel="nofollow">@Cell</a>;
 
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//    if (cell == nil) {
//        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//    }
 
 
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell = [[[MyTableViewCell alloc ] init] autorelease] ;
    }
 
 
    //send an event so that the cell can be formatted
    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, "cellForRowAtIndexPath");
		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 nil;
		}
	}
	lua_pop(L, 1);	
 
    //cellText is set by calling tableView:setCellText() from the 
    //Gideros event function called above
    cell.textLabel.text = self.cellText;
    return cell;
}

My question is:

how to extend a ui class in individual file,not edit uikit source code,etc write a MyTableView.mm ?
and in lua, require same plugin ,require "ui", use same api method (addToRootView ,removeFromRootView) manage this new ui class ,MyTableView ?

Comments

Sign In or Register to comment.