Reputation: 57
I'm new in iOS development, and i'm looking for some help on my UITableView issue.
Well, i was studying everything about the UITableView code, and, during the development, when i'm trying to reuse the identifier (in case that there's no cell to create on the interface), the XCode shows the message:
"No visible @interface for 'UITableView' declares the selector 'initWithStyle:reuseIdentifier:"
There's the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(cell ==nil)
{
cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
Could someone help me here?
Upvotes: 2
Views: 5370
Reputation: 167
Saved my day. Replaced my code - commented, with this code -and presto it worked. Not sure why though!! but thanks.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// static NSString *identifier = @"cell";
// UITableViewCell *cell = [tableView dequeueReusableCellWithIndentifier:@"cell"];
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
Upvotes: 0
Reputation: 8106
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
should be
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
you should allocate a UITableViewCell
not UITableView
like what you've done here.
//should be **UITableViewCell**
cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
and dont forget to return it later.
return cell;
Upvotes: 4
Reputation: 35636
The error message says it all. You are calling the method on a wrong class...
You'll just have to set the class & alloc a UITableViewCell
instead of UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
// ...
Upvotes: 1
Reputation: 2481
use the following code instead of your code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
}
Upvotes: 0