[英]Objective-C - Table View Controller - Expected expression
我是Objective-C和iOS單詞的初學者,我嘗試學習如何為iOS做出色的應用程序。
我嘗試創建一個TableViewController,所以我創建了一個類,但是這段代碼有一些問題,我不知道為什么。 我在注釋的代碼中描述了所有內容。
這是代碼。
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
謝謝你的幫助 !
在nimNameOrNil
initWithNibName
中存在問題。 您要做的就是:更改此行
self = [super initWithNibName:<#nibNameOrNil#> bundle:nibBundleOrNil];
至
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];
注意: <#nibNameOrNil#>
與nibNameOrNil
<#nibNameOrNil#>來自代碼意義自動填充。 您會注意到Xcode中的文本是灰色的。 您需要在其上鍵入nibNameOrNil。 好像是Xcode的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.