views:

118

answers:

2

Hello friends.

I have a different problem.

I am creating my TableViewCells like:


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    UILabel *label = nil;

    NSString *cellIdentifier = [NSString stringWithFormat:@"Cell_%i", indexPath.row];

    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
        //cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
        label = [[UILabel alloc] initWithFrame:CGRectZero];
        [label setLineBreakMode:UILineBreakModeWordWrap];
        [label setMinimumFontSize:FONT_SIZE];
        [label setNumberOfLines:0];
        [label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
        [label setTag:1];


        [[cell contentView] addSubview:label];

    }
return cell;
}

as you see, i have cells with identifiers like "Cell_0 , Cell_1, etc"

and in a function which is not a TableView Method, i want to use this cells by calling their identifiers. i do this like:


UITableViewCell *cell  = [myTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]];
    }
UILabel *label = (UILabel*)[cell viewWithTag:1];

cant i use like this?

i am trying to change the color of label in the cell i try to access, but i cant. cell is not nil, but label is always nil. what should i do?

how can i understand if its the cell i want or an empty cell?

+1  A: 
NSString *cellIdentifier = [NSString stringWithFormat:@"Cell_%i", indexPath.row];

cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

This defeats the whole purpose of cell reuse!

You should use the same cell identifier for all cells that "look" the same (i.e. have the same subviews), and only change their contents.

To get a cell you created for a particular row, use [tableView cellForRowAtIndexPath:indexPath].

Adam Woś
i think i could not tell my problem good.i have a method named getCellToBeModified.inside it there is not indexPath.but i need to use my cell inside this method. so, i know my CellIDS which are hold in a Mutable Array, i am trying to access that cell by using:UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"Cell_%i", myCellID]];}i need a solution wtihout delegate methods
cenk ebret
+1  A: 

ok i have solved my problem by filling all indexPaths in an array and while calling a cell, calling the index path from that array. thanks for answers

cenk ebret