1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellidenti = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellidenti];

    if(cell == Nil)
    {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidenti];
    }
    cell.textLabel.text = isActive?searchData[indexPath.row]:tableData[indexPath.row];
    cell.detailTextLabel.text = isActive?searchNumberData[indexPath.row]:tableNumberData[indexPath.row];   
    return cell;
}

i am not getting perfect view and i am not using storyboard.

Jitendra
  • 5,055
  • 2
  • 22
  • 42
Priyank Gandhi
  • 626
  • 2
  • 8
  • 21

4 Answers4

3

You are not using correct way of reusable cell's instance and also use static cell identifier. so for more info see below code in edited section....

-UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellidenti = @"Cell";// edited here.....
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidenti];// edited here

    if(cell == Nil)
    {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidenti];
    }
    cell.textLabel.text = isActive?searchData[indexPath.row]:tableData[indexPath.row];
    cell.detailTextLabel.text = isActive?searchNumberData[indexPath.row]:tableNumberData[indexPath.row];   
    return cell;
}
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
1

Error is in this line UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellidenti]; This will return UIView, not UITableviewCell. Instead, you can use below line.

[tableView dequeueReusableCellWithIdentifier:cellidenti];
Mani
  • 17,549
  • 13
  • 79
  • 100
1

Two things i have observed in code

1) Use correct way of cell reusability using dequeueReusableCellWithIdentifier (as others already suggested). Also have a look at another way of reusability of cell here using dequeueReusableCellWithIdentifier:forIndexPath:.

2) Try to use nil instead of Nil. Have a look at this thread.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellidenti = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidenti];

    if(cell == nil)
    {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidenti];
    }
    cell.textLabel.text = isActive?searchData[indexPath.row]:tableData[indexPath.row];
    cell.detailTextLabel.text = isActive?searchNumberData[indexPath.row]:tableNumberData[indexPath.row];   
    return cell;
}
Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
0

USe dequeueReusableCellWithIdentifier for creating reuse instance

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101