xmartlabs/XLForm

how to change buttons' action and events of custom row in View Controller

HelloButler opened this issue · 4 comments

inside a ViewController.m

//cellImageBtn is a UIButton define in a custom upLoadImageCell 
   {
row =[XLFormRowDescriptor formRowDescriptorWithTag:@"uploadImage" rowType:XLFormRowDescriptorTypeUploadImage];
   [row.cellConfigAtConfigure setObject:@"YES" forKey:@"cellImageBtn.hidden"];//this works ok
    [[row.cellConfigAtConfigure objectForKey:@"cellImageBtn"] addTarget:self action:@selector(photoBtnTap) forControlEvents:UIControlEventTouchUpInside];// this is not working
}

-(void)photoBtnTap{
//do sth...
}

anyone have idea?

cellConfigAtConfigure cannot be used like that to get properties of the row. It is just used to store values of properties which will later be set on the row. What you could do is setting the controller as a delegate to the row

I am new to Objective c,
how to do that? a example will be appreciated :)
this is normal way to do that, but with xlfrom, there's not such thing like cell instance;

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PreferentialCell *cell = [tableView dequeueReusableCellWithIdentifier:@"preferentialCell" forIndexPath:indexPath];

    YXHGoods *goods = self.dataArray[indexPath.row];
    cell.goods = goods;

    __weak typeof(self) wself = self;
    cell.onClickShareButtonHandler = ^(YXHGoods *model) {
    [wself _handleShareEventWithGoods:model]; //button in PreferentialCell
    };
    cell.onClickCommentButtonHandler = ^(YXHGoods *model) {
    [wself _handleCommentEventWithGoods:model];////button in PreferentialCell
    };

    return cell ;
    }

I did this in Swift but there should be a way in Objc as well:

@objc protocol RateCellDelegate: class {
    func rated(value: Float) -> Void
}

class XLFormRatingCell : XLFormBaseCell {
    
    @IBOutlet weak var rateTitle: UILabel!
    @IBOutlet weak var ratingView: XLRatingView!
    @objc weak var delegate: RateCellDelegate?

    // ....

    @objc func rateChanged(_ ratingView : XLRatingView){
        rowDescriptor!.value = ratingView.value
        delegate?.rated(value: ratingView.value)
    }
}

And in the view controller:

row.cellConfigAtConfigure["delegate"] = self

I did it alternative way, thx anyway:)