あなたは以下のメソッドを実装するクラスにすべてのテーブルのためのUITableViewDelegateとUITableViewDataSourceを設定する必要があり
:UITableViewDataSourceについて
を:これらの方法として
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
と
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
呼び出し元のテーブルビューに渡された場合は、テーブルビューの正しいデータを返すのは簡単です(既にstoriしています) NSMutableArrayのng)。あなたはまだあなたの配列の異なる内容を表示する必要がありますが、私はあなたがそうすることを管理すると信じています。 NSIndexPathは基本的に配列のどの部分を表示するかを指示します。あなたがグループ化されていないテーブルで作業していることを、今のところ、と仮定すると、あなたは簡単な新しいセルを作成し、indexPathによって決定され、あなたの配列の内容とそれを埋めるでしょう:他のデータ・ソースで
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyNiceIdentifier";
cell = [aTableView dequeueReusableCellWithIdentifier:NavigationCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.tag = 500;
}
cell.textLabel = [myArray objectAtIndex:indexPath.row];
}
そのアレイの方法、あなたは簡単なリターンカウントは:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == myFirstTableView) {
return [myFirstArray count];
}
}
あなたはおそらく最も頻繁に使用されますUITableViewDelegateの方法はこれです:あなたは、戻りに使用
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
指定されたindexPathでのセルの望ましい高さ
設定データソースとデリゲートはやっほど単純です:
myTableView.delegate = ...
myTableView.dataSource = ...
は、このマニュアルを参照してください:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate
も、このドキュメントを参照してください:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
が応答をいただき、ありがとうございます。しかし、私は各テーブルのためにこれを実装する方法を知らない。私は試してみました。第二のテーブルは最初のものを模倣しています。 "*"はどういう意味ですか?私は助けに感謝します。 – motoxrider365
cell.textLabel = [myArray objectAtIndex:indexPath.row]; < - これは、テーブルを区別する必要がある場所です。どのテーブルがメソッドを呼び出すかに応じて、条件付きでデータを返す必要があります(if-then、switchなどを使用して)。あるいは、dataSourceとして動作し、それぞれのテーブルに対して委譲するオブジェクトを作成することもできます。 *は変数がメモリアドレスへのポインタであることを意味します(NSArray * myArrayはNSArrayを指します)。 –