user1468157
user1468157

Reputation: 55

how to set hidden property to NO for particular cell in tableView

I am new to iphone.I have a small doubt that is,I have a table view with 66 rows initially i placed a progress view to all rows but in viewdidload i set it to hidden for all those like below in tableViewClass(ShowProgressViewCont)

cell.progressView.hidden = YES;

here (cell) is the the reference of the CustomCell class.In this class i declare a progress view and setter and getter properties also be set here in this class

here in tableview there is a download button in each cell.If we click on that download button(for example in 66th cell).we have to remove the hidden property to the progress view for that particular 66th cell only.The remaining 65 cells should have the progress view in hidden only like that for all cells.

If any body know this please help me....

Upvotes: 0

Views: 373

Answers (5)

john.k.doe
john.k.doe

Reputation: 7563

your model should be tracking the progress for every button clicked. for purposes of this answer, let's say the model is held in a property called modelInformationArray (which would contain an array of objects that relate to each cell in the table)

when the download button is clicked for a cell, modelInformationArray is modified in such a way that its object knows a download is being processed for it.

that object reports the downloading processing in a member called downloadingProcessingStarted. there are many other ways to do that part.

to get to the answer to your question … to then unhide the progress view, you would do something as follows in your UITableViewDataSource implementation of tableView:cellForRowAtIndexPath: .

- (UITableViewCell*)tableView:tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    YourCustomCell* cell = ...
    if ([[self.modelInformationArray objectAtIndex:indexPath.row] downloadingProcessingStarted])
        cell.progressView.hidden = NO;
}

Upvotes: 0

Hermann Klecker
Hermann Klecker

Reputation: 14068

Are you familiar with the concept of table cells being reused?

viewDidLoad is not an appropriate place to manipulate the content of a single cell. It may work fine if the table is so small that all of its cells fit on the screen (in both orientations). When there are more cells in the table than beeing displayed on the screen, then those cell that became invisible recently is being reused and displayed again. So if there are 6 cells on the screen at a time then table cell no. 7 (sometimes 8) will be identical with cell no. 1.

cellForRowAtIndexPath would be a better place to hide/unhide certain views of a cell. If it is a custom cell already then the cell's layoutSubViews could be appropriate, too. However, only in the tableViewController's cellForRowAtIndexPath you will have easy access to both, the table's data and the associated cell.

cellForRowAtIndexPath is called every time when a cell is about to become visible. Use the default reusing-mechanism to ensure that a proper cell object will be reused. It is pretty much straight forward.

Upvotes: 2

Abhishek
Abhishek

Reputation: 2253

Hide your progress view in your custom cell means make the default property of every progress view is hidden ,and then your button click method .

CutomeCell *cell = (CutomeCell *)[[button superview] superview];
[cell.progressView setHidden:NO];
NSIndexPath *rowToReload = [[self tableView] indexPathForCell:cell];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
[UITableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];

may this help you ...

Upvotes: 0

Atif
Atif

Reputation: 1220

First set the row number in your download button in CellForRowAtInedexPath

   downloadButton.tag = indexPath.row
   [downloadButton addTarget:self action:@selector(actionDownload:) forControlEvents:UIControlEventTouchUpInside];

in actionDownload, make the IndexPath from button.tag and get the cell from "cellForRowAtIndexPath:", finally update via reloadRowsAtIndexPaths: withRowAnimation:

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

Get the cell at index 65 and then cast it to your custom cell

UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:64 inSection:0]];

YourCustomCell *customCell = (YourCustomCell *)cell;
customCell.progressView.hidden = NO;

Upvotes: 0

Related Questions