質問

I am using custom cell type UITableview.

The custom cell just has two lines of text one below other - key value pair.

The data creating the table is an array sorted based on key.

I need to check whether the top some of the top keys are to be be a part of the table or not.

If not I need to skip the use of those key value pairs and would then use the left array data to create the table. e.g index 0,1,2 may have to be skipped.

When I try to put this condition in cellForRowAtIndexPath: like this

if (key is to be used)
{
    cell.key.text = [NSString stringWithFormat:@"%@", [mrow1 etimov]];

    cell.value.text = [NSString stringWithFormat:@"%@", [mvalue1 valor]];
}

What this does is that instead of not creating the top 3 cells (say) it creates the cells without actual data of key value but the labels I used in the custom cell for key and value.

What do I change to get rid of the unwanted top cells?

役に立ちましたか?

解決

You should change number of rows in tableView:numberOfRowsInSection:. Obviously, if you remove three rows, number of rows will change.

It will also affect the indexPath in tableView:cellForRowAtIndexPath: method. After skipping first three items, indexPath.row = 0 should correspond to third item in item array.

In other words:

numberOfRows = items.count - numberOfSkippedRows
item = items[indexPath.row + numberOfSkippedRows]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top