I confused about my custom cell. I am creating custom cell including the 2 labels and one button. Now how can I set the button click event as I am using this cell in another file ?
开发者_运维技巧any suggestion ?
Thanks..
When one create the button, one need to set the action for that (The function,which respond to the user interaction),
So this action will always receive the touch event for UIButton regardless where your are adding your UIButton
as subview , means you can add your button as subview in any class which is inherited from UIView
EDITED:
you can either define the action ifor your UIButton
in CustomCell OR in your TableView 's
class, But the decision could be taken based on the action of your UIButton
, if the button change the state of your CustomCell
then add it in your CustomCell
and if the button do some external operation (like sending request to server) then add it in the same class where you create the CustomCell.
You can set the object of that another file where you use that custom cell as a target of that button.
For Ex.
In myOtherFile.m
myCell *cell = myCell cell.targetController = self;
In myCell.m
UIButton *btn = [UIButton buttonWithType:custom];
[btn addTarget:targetController action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
精彩评论