Reputation: 646
- (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.
Upvotes: 1
Views: 177
Reputation: 11233
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;
}
Upvotes: 1
Reputation: 17585
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];
Upvotes: 1
Reputation: 20021
USe dequeueReusableCellWithIdentifier
for creating reuse instance
Upvotes: 0
Reputation: 17535
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;
}
Upvotes: 3