私は自分のモバイルアプリケーションクラスで課題を与えられました:iphone用のカラーゲームアプリを作成してください)以下の貼り付けられたviewcontroller.hファイルの最上部にあります。ストーリーボードとUITableViewデータソースとの混乱:セルにテキストを表示する方法
私はObjective-CとCocoaの新機能ですが、このアプリケーションで多くの問題のトラブルシューティングと修正を行っています。私が今いる問題は、UITableViewCellsを適切に初期化してビューに送信する方法がわからないことです。オンラインで見つかったチュートリアルのすべてでは、UITableViewとセルの異なる属性を変更するためにデータソースメソッドを使用するので、私は混乱しています。私はこれらのメソッドが私がすでに配置したコントロールとどのように相互作用するのかよく分かりません。ストーリーボードファイルで追加したため、データソースコードでtableview属性を定義するのではなく、混乱しています。
私の直接の問題は、自分のプログラムがセルtextlabelとdetailtextlabelに適切なテキストを表示しないことです。
私はUITableViewとUITableViewCellのチュートリアルをオンラインで見てきましたが、何年も前からあり、ストーリーボードの出現によって私がこれらのコントロールを扱う方法が変わったかどうかはわかりません。
私が書いたすべてのコードは、viewcontroller.mまたはviewcontroller.hファイルにあります。セルおよび表示テキストと詳細テキストを呼び出す必要がありViewController.mファイル内
方法:
:私はviewcontroller.mファイルの一番下に呼ばき-(IBAction)enterClicked
{
//On enter- send instance colors to the colorTable row[i], perform comparisons and append the resulting symbols to the instanceResults String. Send instanceResults string to the resultTable row[i]. When game counter reaches 6, gameOver. If on comparisons check, the instanceColors are the same as the gameColors, then the player wins.
[self checkForLoss];
if(!self.gameOver)
{
resultOfGuess = [self comparePlayerInputToGameColors:guessColors];
[listOfGuesses addObject:guessColors];
[listOfOutcomes addObject:resultOfGuess];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_numberOfTurnsPlayed inSection:0];
UITableViewCell *thisCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
thisCell.textLabel.text = [self.listOfGuesses lastObject];
thisCell.detailTextLabel.text = [self.listOfOutcomes lastObject];
[guessColors setString:@""];
if([self checkForWin:resultOfGuess])
[UpdateLabel setText:@"You have won!"];
else
[UpdateLabel setText:@""];
self.colorCounter = 0;
self.isStepOne = YES;
_numberOfTurnsPlayed++;
}
else
{
if([self checkForLoss])
[UpdateLabel setText:@"You have lost!"];
}
}
のUITableViewのデータソースメソッド
#pragma mark - UITableViewDataSource protocol
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
return @"Guesses: Results:";
return 0;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 6;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
return cell;
}
私の質問は次のとおりです。ストーリーボードでコントロールを作成した場合、データソースメソッドでコントロールのプロパティを変更できますか? uitableviewのセルにテキストを正しく表示するにはどうすればよいですか?
編集/更新:ありがとうございます、私はあなたのアドバイスjrturtonを使用しましたが、今は私の問題の原因かもしれない特異なものを発見しました。私はViewControllerをファイル内を呼び出し、データソースのメソッドが同じメソッドとプロパティを呼び出すことができるように持っていることを考えるのUITableViewController
:のViewControllerへのUIViewController:私のviewController.hファイルに私が
のViewControllerから私のヘッダーを変更しました他のUITableViewチュートリアルファイルでもこれが行われています。キャッチされない例外により「NSInternalInconsistencyException」、理由に
アプリを終了:と私はコンパイルしようと、私はこのエラーを取得する - のUITableViewController:「
問題は、私はViewControllerををread--するヘッダーを変更したときということです - [UITableViewController loadView]は "2-view-3"ペン先をロードしましたが、UITableViewを取得しませんでした。 私はちょうど:ヘッダファイルでUIViewControllerを使ってもうまくコンパイルされます。
アイデア?
更なる更新:私のストーリーボードでは、使用可能なViewControllerオブジェクトはUIViewControllerオブジェクトであることに気付きましたが、他のチュートリアルファイルではこのViewControllerオブジェクトはUITableViewControllerオブジェクトです。これは私の問題だと思いますが、UIViewControllerオブジェクトをUITableViewControllerに切り替えることができません。私ができることは、私が望むものではない新しいものを作り出すことです。私は想像しています。