简体   繁体   中英

Objective-C - Table View Controller - Expected expression

I'm beginer in Objective-C and iOS word, I try to learn how to do nice apps for iOS.

I try to create a TableViewController, so I make a class, but I have some problem with this code, and I don't know why. I describe all in the code in the comments.

This is Code.

BooksTableViewController.m 

import "BooksTableViewController.h"

@implementation BooksTableViewController



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil //Semantic Issue - Designated initializer missing a 'super' call to a designated initializer of the super class
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];// Parse Issue - Expected expression

if(self){
    self.title = @"Books";
    self.tabBarItem.image = [UIImage imageNamed:@"books8.png"];
    self.imiona = @[@"Pan Tadeusz", @"Potop", @"Lalka", @"Uczta dla wron", @"Symfonnia C++"];
}
return self;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.imiona.count;
}

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

if(cell == nil){
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Title"];
}

cell.textLabel.text = self.imiona[indexPath.row];

return cell; 
}

@end

Thank You for help !

In initWithNibName at nimNameOrNil there is the problem. All you have to do is: Change this line

self = [super initWithNibName:<#nibNameOrNil#> bundle:nibBundleOrNil]; 

to

self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];

Notice: the <#nibNameOrNil#> with nibNameOrNil

<#nibNameOrNil#> is from the code sense auto fill. You'll note that the text in Xcode is gray. You need to type nibNameOrNil over it. Seems like an Xcode bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM