Reputation: 9541
I keep getting Expected Identifier in my if statement
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//NSDate *object = _objects[indexPath.row];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]];
// expected identifier
}
Upvotes: 1
Views: 3893
Reputation: 881
You are dequeueing a cell with the identifier "Cell" and creating a new one with identifier "Cell1" that's why you always end up in the if statement.
Change
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
to
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Upvotes: -1
Reputation: 104082
I don't know why you're getting that, but when you use dequeueReusableCellWithIdentifier:forIndexPath, you don't need that if clause at all. That dequeue method is guaranteed to create a cell.
Upvotes: -1
Reputation:
Here:
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]];
^ ^
You have an extra pair of brackets. The outermost pair is superfluous.
Upvotes: 9