xmartlabs / XLForm

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
MIT License
5.77k stars 953 forks source link

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

Closed HelloButler closed 5 years ago

HelloButler commented 5 years ago

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?

mats-claassen commented 5 years ago

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

HelloButler commented 5 years ago

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;

mats-claassen commented 5 years ago

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
HelloButler commented 5 years ago

I did it alternative way, thx anyway:)