UITableViewCell

Discussion in 'iOS Programming' started by yaniv92648, Mar 1, 2010.

  1. yaniv92648 macrumors member

    Joined:
    Oct 26, 2009
    #1
    Hi,

    - (UITableViewCell *)tableView:(UITableView *)ttableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Temporary - should get all details from xml
    static NSString *CellIdentifier = @"CellIdentifier";
    // If a cell with this identifier is already created then it will be reused
    UITableViewCell *cell = (UITableViewCell *)[ttableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
    // If a cell with this identifier isn't already created then it will be created and assigned an identifier
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    UITextView *tmpTxtView = [[UITextView alloc] initWithFrame:CGRectMake(97, 30, 80, 40)];
    [tmpTxtView setUserInteractionEnabled:NO];
    [tmpTxtView setBackgroundColor:[UIColor clearColor]];
    [tmpTxtView setTextColor:[UIColor whiteColor]];
    [tmpTxtView setFont:[UIFont fontWithName:mad:"Arial" size:16]];
    [tmpTxtView setFont:[UIFont boldSystemFontOfSize:16]];
    [tmpTxtView setTextAlignment:UITextAlignmentLeft];
    [tmpTxtView setTag:kfeeTag];
    [self setFee:tmpTxtView];
    [tmpTxtView release];
    [cell.contentView addSubview:fee];
    }else{
    fee = (UITextView *)[cell.contentView viewWithTag:kfeeTag]; // // Returns UIView instead of UITextView!
    }
    [fee setText:mad:"A"];
    return cell;
    }

    this line: fee = (UITextView *)[cell.contentView viewWithTag:kfeeTag];
    returns a UIView instead of a UITextView and i don't understand why.

    Thanks.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    If you use code tags your code is much more readable :)

    Code:
    
    - (UITableViewCell *)tableView:(UITableView *)ttableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{	
    	// Temporary - should get all details from xml
    	static NSString *CellIdentifier = @"CellIdentifier";
    	// If a cell with this identifier is already created then it will be reused
    	UITableViewCell *cell = (UITableViewCell *)[ttableView dequeueReusableCellWithIdentifier:CellIdentifier];
    	if(cell==nil){
    		// If a cell with this identifier isn't already created then it will be created and assigned an identifier
    		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    		UITextView *tmpTxtView = [[UITextView alloc] initWithFrame:CGRectMake(97, 30, 80, 40)];
    		[tmpTxtView setUserInteractionEnabled:NO];
    		[tmpTxtView setBackgroundColor:[UIColor clearColor]];
    		[tmpTxtView setTextColor:[UIColor whiteColor]];
    		[tmpTxtView setFont:[UIFont fontWithName:@"Arial" size:16]];
    		[tmpTxtView setFont:[UIFont boldSystemFontOfSize:16]];
    		[tmpTxtView setTextAlignment:UITextAlignmentLeft];
    		[tmpTxtView setTag:kfeeTag];
    		[self setFee:tmpTxtView];
    		[tmpTxtView release];
    		[cell.contentView addSubview:fee];
    	}else{
    		fee = (UITextView *)[cell.contentView viewWithTag:kfeeTag];                     //              // Returns UIView instead of UITextView!
    	}
    	[fee setText:@"A"];
    	return cell;
    }
    
    As to why it's not working... what is kfeeTag? Is there any chance two views have the same tag? If they do I imagine this is the problem...
     
  3. yaniv92648 thread starter macrumors member

    Joined:
    Oct 26, 2009
    #3
    I checked..

    and i don't have 2 views with the same viewTag. and kfeeTag is defined like
    this:
    #define kfeeTag 0
    u have another idea why is this happening?
    
    Thank u again.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Try defining it to be something other than 0: I'm pretty sure that's the default tag value so all your views have that tag.
     
  5. yaniv92648 thread starter macrumors member

    Joined:
    Oct 26, 2009

Share This Page