I am adding download button in cell’s accessory view ..my code is
button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:@"download.png"];
[button setImage:image forState:UIControlStateNormal];
//[button setTitle:@"Download" forState:UIControlStateNormal];
[button setFrame: CGRectMake( 110.0f, 3.0f, 80.0f, 30.0f)];
[button addTarget:self action:@selector(someAction) forControlEvents:UIControlEventTouchUpInside];
button.tag = indexPath.row;
cell.accessoryView = button;
And I want to pass file name from cell ‘s index path but this is not working It only takes first row…
- (void)someAction {
[self.activityIndicator startAnimating];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [NSString stringWithFormat:@"/%@",[metaArray objectAtIndex:button.tag]];
NSLog(@"%@", button.tag);
NSString *path = [NSString stringWithFormat:@"%@/Downloaded Data/%@",[paths objectAtIndex:0],file];
// NSString *loadFileName = [NSString stringWithFormat:@"/%@/%@",Name,file];
[self.restClient loadFile:file intoPath:path];
NSLog(@"Downloaded:%@",file);
}
This crashing because of button.tag = indexpath.row
and if I don’t pass button.tag = indexpath.row it is passing only first row
please help
tagis an integer property. You are trying to print it as object inNSLog. You have to print it like this,NSLog(@"%d", button.tag);Actually you have to assign individual download buttons to each cell.
And define your
someActionmethod like this,