I have a UITableView which has a xib file for UITableViewCell.
On the UITableViewCell I am adding 2 cell data - because I want to implement a two column style. so can't be modified. The cell is a bit complex has more components too, and I want to handle the action of buttons UIControlEventTouchUpInside event. It will download something and need to change the button text after task competition from "Download" to "View" for eg.
The problem it would be solved, if I wouldn't handle the multithreading, async stuff, but needed. So I need to pass the button and an index to the action method, or set a property for the button ( in Java is easy ) but couldn't find it.
The half code looks like this:
[buttonAction addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
and need something like this:
-(void)buttonPressed:(UIButton*)button index: (int) index
{
}
In other question the index is passed with buttonAction.tag = index
but if I chnage that property, than I think it wont work the
UIButton *buttonAction = (UIButton *)[cell viewWithTag:205]; statement anymore at
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Any suggestion how to handle this case?
You can subclass UIButton
class and have properties for all the information you need. Then you add action to your button for TouchUpInside with @selector(buttonPressed:)
-(void)buttonPressed:(YourCustomButton *)sender // or id and then you check it's class and cast to your custom button class
{
// work with sender.yourProperty
}
EDIT
[button setTitle:@"Download" forState:UIControlStateNormal];
[button setTitle:@"View" forState:UIControlStateReserved];
and then work depending on your title: button.currentTitle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.