異なるセクション数で異なる行数を管理するにはどうすればよいですか? 行とセクションの数は固定されていません。他のクラスの別のテーブル ビューに依存します。xxx セクション ヘッダーの場合、5 行が含まれ、別のセクション ヘッダーには 4 行が含まれるとします。セクション ヘッダーは、他のクラスのテーブル ビューのアカウント タイトルです。
1858 次
5 に答える
2
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3; or [yourarray count] // 3 sections 0,1,2
}
異なるセクションの異なる行数の場合
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the sections.
if( section == 0) // first section with 5 rows
return [[yourarray objectAtIndex:section] count];
if( section == 1) // 2nd section with 4 rows
return [[yourarray objectAtIndex:section] count];
if( section == 2) // 3rd section with 57rows
return [[yourarray objectAtIndex:section] count];
}
于 2012-04-20T05:00:02.730 に答える
1
テーブルビューではデリゲートメソッド。それは持っています:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return data.count;
}
と
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [data objectAtIndex:section].count;
}
これら2つの方法でセクション番号と行番号を設定できます。
もちろん、データを2次元配列に構成する必要もあります。
于 2012-04-20T04:57:11.510 に答える
1
それが役に立てば幸い:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if( section == 0)
return [array count];
if( section == 1)
return [array2 count];
if( section == 2)
return [array3 count];
}
于 2012-04-20T05:06:56.460 に答える
0
その本当にシンプルな、tableViewデリゲートの下で使用-
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// return your another table view's array count here, on which no of sections depends.
}
// Customize the number of rows in the table view.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// use like this
int noOfRows = 0;
if(section == 0)
{
noOfRows = x;
}
else if(section ==1)
{
noOfRows = y;
}
.
.
.
else
{
noOfRows = z;
}
return noOfRows;
}
x、y、zはここではNSIntegerです
于 2012-04-20T04:52:55.630 に答える
0
これを試して
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0){
return 5;
}
if (section == 1){
return 10;
}
//etc.
}
于 2012-04-20T05:00:12.513 に答える