0
私のアプリでグループ化テーブルビューを使用しています。私はテーブルに2つのセクションを持っています。最初のセクションは3行、2行目は10行以上です。セクションをスクロールすると、5行目の5行目以降のセクション1の行が表示されます。私は何をすべきか。ここでIphoneのグループ化されたテーブルビュー
は私のコードです...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 3;
break;
case 1:
return 8;
break;
default:
break;
}
return 5;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section==0)
{
if (indexPath.row==0)
{
UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
[Name setText:@"First Name "];
[cell.contentView addSubview:Name];
UITextField *textName=[[UITextField alloc]initWithFrame:CGRectMake(140, 10, 150, 20)];
[email protected]"Enter First Name";
[textName setBorderStyle:UITextBorderStyleNone];
textName.clearButtonMode = UITextFieldViewModeWhileEditing;
textName.keyboardType=UIKeyboardTypeDefault;
textName.returnKeyType=UIReturnKeyDone;
textName.delegate=self;
[cell.contentView addSubview:textName];
}
if (indexPath.row==1)
{
UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 110, 20)];
[Name setText:@"Middle Name"];
[cell.contentView addSubview:Name];
UITextField *textName=[[UITextField alloc]initWithFrame:CGRectMake(140, 10, 150, 20)];
[email protected]"Enter Middle Name";
[textName setBorderStyle:UITextBorderStyleNone];
textName.clearButtonMode = UITextFieldViewModeWhileEditing;
textName.keyboardType=UIKeyboardTypeDefault;
textName.returnKeyType=UIReturnKeyDone;
textName.delegate=self;
[cell.contentView addSubview:textName];
}
if (indexPath.row==2)
{
UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
[Name setText:@"Last Name "];
[cell.contentView addSubview:Name];
UITextField *textName=[[UITextField alloc]initWithFrame:CGRectMake(140, 10, 150, 20)];
[email protected]"Enter Last Name";
[textName setBorderStyle:UITextBorderStyleNone];
textName.clearButtonMode = UITextFieldViewModeWhileEditing;
textName.keyboardType=UIKeyboardTypeDefault;
textName.returnKeyType=UIReturnKeyDone;
textName.delegate=self;
[cell.contentView addSubview:textName];
}
}
if (indexPath.section==1) {
if (indexPath.row==0) {
[email protected]"1";
}
if (indexPath.row==1) {
[email protected]"2";
}
if (indexPath.row==2) {
[email protected]"3";
}
if (indexPath.row==3) {
[email protected]"4";
}
if (indexPath.row==4) {
[email protected]"5";
}
if (indexPath.row==5) {
[email protected]"6";
}
if (indexPath.row==6) {
[email protected]"7";
}
if (indexPath.row==7) {
[email protected]"8";
}
}
return cell;
}
お返事ありがとうございました...その作業:) –
@Alex私はこれをよりよく理解したいと思います。なぜこの状況は2つの識別子を必要としますか?各セクションには常に識別子が必要ですか?ありがとう。 –
私の編集を見てください。 –