Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yaniv92648

macrumors member
Original poster
Oct 26, 2009
96
0
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.
 
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...
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.