0
我在我的應用程序中使用分組表格視圖。我在表中有2個部分。第一部分有3行,第二部分有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) {
cell.textLabel.t[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;
}
嘿感謝您的回覆...它的工作:) – 2011-02-01 10:02:37