objective-c accessing methods from custom cell

后端 未结 4 1339
广开言路
广开言路 2021-01-19 23:56

ok, this is maybe a newbie question but i need help with it.. I have a someview.m and in it a custom cell which is defined in customCell.h and .m So in someview.m i have

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 00:50

    You need to use delegate. Custom cell init method will take delegate of someview. To textFeild in CustomCell set this delegate. Something link this In CustomCell.h have a class variable

    {
    UIViewController *target;
    }
     - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withtarget:(UIViewController *)_target;
    

    In CustomCell.m

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withtarget:(UIViewController *)_target
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code 
             target = _target;
    }
    

    // You can now use this call [target printStuff];

    In someView.m cellForRow method call this init method to initialise cell.

    cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier withtarget:self ];
    

提交回复
热议问题