2016-08-29 11 views
0

View Controllerを変更したときにクラッシュが発生する問題が発生しています - 基本的には、ユーザーから検索用のデータを取得するVCがあります有効なセルを返すcellForRowAtIndexPathにもかかわらずUITableViewがクラッシュする

2016年8月29日20:48:03.950のMyApp [2596のUITableViewに表示された結果、

クラッシュログ(UITableViewController、普通のUIViewController内部テーブルビューを使用していません) :60877] ***アサーションエラー - [SearchResultsTable _confi gureCellForDisplay:forIndexPath:]、/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:7971

2016-08-29 20:48:03.961 MyApp [ 2596:60877]キャッチされていない例外 'NSInternalInconsistencyException'のためアプリを終了しています、理由: 'UITableView(;層=; contentOffset:{0、0};***ファースト・スロー・コール・スタック:

(最初のコール・スタックをスローする:contentSize:{375、1128}>)は、そのデータ・ソースからセルを取得できませんでした(レイヤー= contentOffset:{0,0}; contentSize:{0、0}

しかし私は、私は私の実装が正常細胞に戻すことを肯定的だ、この問題はあなたのcellForRowAtIndexPath機能でセルを返さないことで引き起こされることを読みました。 (私はどこか別の関数のコードをテストし、cell実際に値を持っており、ゼロではありません。)

コード:いくつかのブレークポイントを置いた

@property searchResultCell * cell;

-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    _cell = [self dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 

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

    [[_cell txtDate] setText:@"test"]; 
    return _cell; 
} 

このコードセクションは、UITableViewクラスにもかかわらず、delegateとdataSourceが正しく設定されているにもかかわらず、実行されることはありません。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

_SearchResultsTableDelegate = [[searchResultsTable alloc] init:[self specifiedSerial]]; 

[[self SearchResultsTable] setDelegate:_SearchResultsTableDelegate]; 
[[self SearchResultsTable] setDataSource:_SearchResultsTableDelegate]; 
} 

宣言:

@property (weak, nonatomic) IBOutlet UITableView *SearchResultsTable; 
@property searchResultsTable * SearchResultsTableDelegate; 

を誰もが右に私を指すことができれば検索のための

のviewDidLoadは(。[self SpecifiedSerial]はセグエが起こる前に、それはNSString*である以前に設定されている)VC結果ここの方向に、それは非常に感謝するだろう!

+0

どこでいつ呼び出すことができますか? –

+0

このUITableViewCellを試してください。* _cell = [yourTableView dequeueReusableCellWithIdentifier:@ "cell"]; – Signare

+0

より多くのコードを表示すると、なぜデリゲートが自身をテーブルデリゲートとして設定していないのですか? – Wain

答えて

1

使用このコード:

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

の代わりに:

-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    _cell = [self dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 

編集:

あなたnumberOfRowsInSectionnumberOfSectionsInTableViewは不正確であると思われます。

は、このコードを試してみてください。

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

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    _cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath]; 

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

    [[_cell textLabel] setText:@"test"]; 
    return _cell; 
} 
+0

悲しいことに、問題を修正していませんでしたが、変更後に警告が表示されました。 – Swemoph

+0

'numberOfSectionsInTableView'と' numberOfRowsInSection'が実装されていますか? –

+0

さらにコードを投稿すると便利です。 –

0

は、私は真剣にあなたが使用しているデリゲートメソッドを疑います。私はこの

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

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

    [[_cell txtDate] setText:@"test"]; 
    return _cell; 
} 
1

はおそらく理由は、あなたがcellForRowAtIndexPathメソッドからnilを返すと、再利用可能なセルをデキューに失敗しているで試してみてください

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

cellForRowAtIndexPath方法のこのバージョンを見てきました。

利用コード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    searchResultCell *cell; 
    cell = (searchResultCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"]; 

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

    [[_cell txtDate] setText:@"test"]; 
    return cell; 
} 

そして、ちょうどストーリーボード参照イメージを使用してcell識別子を与えて、カスタムセルを選択するあなたのセルを構成します。 enter image description here

希望します。