IPhone + UITableView + specific row access cell

I use the following method in my application:

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath

In this method with, indexPath.rowI can get the line number of each line.

But I want to access the cell in this row and do only formatting only in this cell.

I beg you, please.

+3
source share
3 answers

Maybe there is a misunderstanding. The method you are quoting is supposed to tell the table which row should be displayed on this indexPath. Thus, whenever a tableView requests this method, it does this because there is no row in this indexPath yet.

The template code generates a new cell or cancels it:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     static NSString *CellIdentifier = @"Cell";

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     }

cell, contentView.

(, cell.textLabel), :

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+2

, , . . :

[[tableView cellForRowAtIndexPath:5 setAccessoryType:UITableViewCellAccessoryNone];

, IndexPath . (, indexpath.row). , , , NSIndexPath NSIndexPath. :

[[tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:5 inSection:0]] setAccessoryType:UITableViewCellAccessoryNone];

, ANYWHERE, ROW/SECTION, tableview.

, -.

+6

You can access the cell visible using the UITableView method -cellForRowAtIndexPath. From the UITableView link:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

Return Value An
object representing the table cell, or zero if the cell is not visible, or indexPath is missing a Range.

However (IMO) cellForRowAtIndexPathis the best place to set up a cell.

+1
source

Source: https://habr.com/ru/post/1724080/


All Articles