2012-05-04 8 views
1

私は、選択する国が設定されたTableViewをプロジェクトに追加しています。新しいファイル(iPad + XIB用のUITableViewサブクラス)を追加し、トリガーIBActionコード(既定の国が正しくない場合はテキストフィールドを編集)を書き、いくつかの接続を行い、空のテーブルビューが表示されます。私はいくつかのチュートリアルを読んでいると私は問題を作ることはできません。ときの単語の負荷を有する配列 - (無効)のviewDidLoad、次の警告でアプリがクラッシュ:既存のプロジェクトにUITableViewを追加する:配列を追加して行を追加するときにクラッシュする

2012-05-04 12:34 :36.740 pruebaF1 [4017:f803] アサーションエラー - [UITableView _createPreparedCellForGlobalRow:withIndexPath:]、/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 2012-05-04 12:34:36.741 pruebaF1 [4017 :f803] *キャッチされない例外 'NSInternalInconsistencyException'のためアプリを終了する理由: 'UITableView dataSourceはtableViewからセルを返す必要があります:cellForRowAtIndexPath:' ...

CountryVieWController接続:

ファイル所有者の接続 アウトレット のdataSource - >ファイルの所有者 デリゲート - >ファイルの所有者 参照アウトレット ビュー - >ファイルの所有者

コード:

// CountryTableVieWController.h 
#import <UIKit/UIKit.h> 
@interface CountryTableVieWController :  
UITableViewController<UITableViewDelegate,UITableViewDataSource> 

{ 
    NSMutableArray *countriesArray; 
    NSArray *countryArray; 
} 
@end 

// CountryTableVieWController.m 
#import "CountryTableVieWController.h" 
#import "pruebaF1SecondViewController.h" 

@interface CountryTableVieWController() 
@end 

@implementation CountryTableVieWController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
    // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 

    countriesArray = [[NSMutableArray alloc] initWithObjects:@"Austria", @"Italy", @"France",nil]; 
} 

ありがとうございます。

+1

を「のtableView:cellForRowAtIndexPath:」ありがとうございました – redent84

答えて

0

UITableViewのデリゲートメソッドを実装する必要があります。

はこれを見ている:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10

私はそれを考えるための最も簡単な方法は、あなたのUITableViewは、細胞内で行くべきか、あなたのコードを求めているということです見つけます。これらのメソッドを使用して、テーブルビューとその内部のUITableViewCellを構成します。

あなたはこのようなものが必要になります:あなたは重要な部分が欠落している

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    [countriesArray count]; 
} 


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

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; 
    } 

    NSString *country = [countriesArray objectAtIndex:indexPath.row]; 
    cell.textLabel.text = country; 
    return cell; 
} 
+0

方法は;)今、テーブルビューは、国のリストが表示されます。提案されたチュートリアルに続き、コードを変更してセルを埋めます。 "file://localhost/Users/luisprado/Developer/pruebaF1%20copia%202/pruebaF1/CountryTable.xib:警告:サポートされていない設定:テーブルビューコントローラー - SELECT COUNTRYビューアウトレットと2つの警告が表示されます。 NIB Name set "接続する"ビュー "はなく、テーブルビューのみです。 – Luis

+0

あなたはそれが働いてうれしいです!あなたの警告についてはあまり確かではありません。インタフェースビルダーで正しくない接続を作成したようです。おそらく、一度に1つの接続を削除して、どこから問題が発生しているのかを確認します。その接続に問題がない場合は、接続し直して次の接続を試みます。 –

関連する問題