Reputation:
I stuck few hours with this problem. I have 3 rows in my tableview. I also use a custom cell contained 1 button and 1 progressbar. The problem is when I click on button at first or second row, the progressbar always show at the third row. I don't know why. But I want to show the progressbar that correspond with row that we clicked.
@interface ViewController_ ()
{
CustomViewCell *cell;
}
@end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = (CustomViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
NSArray *nib;
nib = [[NSBundle mainBundle] loadNibNamed:@"IssueViewCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CustomViewCell class]])
cell = (CustomViewCell *)oneObject;
}
cell.progressBar.hidden = YES;
[cell.downloadButton setTitle:@"Download" forState:UIControlStateNormal];
[cell.downloadButton addTarget:self action:@selector(downloadButtonCliked:) forControlEvents:UIControlEventTouchUpInside];
}
-(void) downloadButtonCliked:(UIButton *)sender{
NSLog(@"Called when press");
cell.progressBar.hidden = NO;
}
Upvotes: 2
Views: 1022
Reputation: 10175
You are not getting the cell in the right way. Your cell instance will always be the last cell loaded by the table view.
You should remove the cell reference, you don't need it.
You can change the code like this:
-(void) downloadButtonCliked:(UIButton *)sender{
NSLog(@"Called when press");
CustomViewCell *buttonCell = (CustomViewCell*) sender.superview.superview;
//if you add the button to the cell view the you should call sender.superview;
buttonCell.progressBar.hidden = NO;
}
Upvotes: 1