views:

47

answers:

2

I have created sample application that insert 12 rows in tableview.And inserted fine.When after inserted my rows i dont want any changes in text during scrolling of tableview.So i checked with indexpath row has value of UITableViewCell , if it has values means return that cell otherwise we created new UITableViewCell.

My sample code is below

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;

}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  {
NSLog(@"GlobalCount = %d",GlobalCount);
return GlobalCount;

}

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

UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)
{
    NSLog(@"cell indexpath row = %d",indexPath.row);
    NSLog(@"cell text = %d",obj.textLabel.text);
    return obj;
}

else {
    NSLog(@"obj==nil");
}


static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

if([DataTable count]>0)
    cell.textLabel.text = [DataTable objectAtIndex:0];
// Configure the cell.
return cell;

}

What my objective is , i dont want update any text (or UITableViewCell)for already created indexpath rows(of cell).So i can check this in cellForRowAtIndexPath , but it always return nil.If i am missing anything ?

I checked using this line

UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)

Plz help me?

Thanks in advance......

+2  A: 

Let the table view decide id it need to update the cell or not. Just remove all the firsdt part of your code and everything will run smoothly.

Don't hesitate to read the UITableView doc.

VdesmedT
After i inserted the all rows it works fine , then i remove all objects from DataTable (its nsmutablarray).Now i scrolling the table there is some text changes in the tableview.So what i inserted data order is not in the tableview . Any thoughts plz help me?
Tamil
Why would you do something like clearing the datasource and still want the table to display its old version ? If you want your array to be cleared and your table to contains itd old values, copy it in your datasource first then clear it.
VdesmedT
Ya. You are correct. Why i want to clear data means, i get data's over udp receive. So my data size is go large and large ,its hang my application.So i want to insert one row from the datasource and delete the data from that array.So there is no large amount of data in my array.This is my thoughts. any help ?
Tamil
I want to display old values in tableview . This is the thing what i exactly want is ?
Tamil
Plz help me ? I searched lot but didnt find good answer so far
Tamil
No way ! The whole UIITableView principle is that cells object are reused so the datasource need to keep all the data. If you have big data to keep, you can try using sqlite to keep them so you don't wast your memory and write data down on the filesystem instead but you wont be able to ask the TableView to keep your data for you and you are in fact happy about it because it would then keep all the cells in memory which would be worse !
VdesmedT
Ya. You are correct.I can able to store all my data's using sqlite db and retrive those information from db.But how can i display it in tableview.So Again we depends the datasource right.so we get data from db and added it to datasource for display in tableview.Am i correct ?
Tamil
I want to display data like( CListCtrl in MFC ).Is there any similar type of control in iphone.
Tamil
You can just query your db as data is needed by CellForRowAtIndexPath
VdesmedT
CListCtr hold the complete view of each line in memory. Hopefully you don't have such memory killer on iPhone.
VdesmedT
How can i query db and displayed data in tableview ?
Tamil
A: 

Thank you for your replies

tamil