iPhone中分组样式的表视图
我想以分组样式将数据库中的数据填充到表视图中。 可以更改记录的数量。(动态更改) 我试过了,但我只能在表视图中创建不同的带有标题的部分 例如:我的数据库有5个字段名称、地址、联系人、工资、技术 所以我想把name字段值放在节的头中,我成功地做到了 但当我试图填充该部分下的其他四个字段值时,它将只填充1个部分iPhone中分组样式的表视图,iphone,cocoa-touch,uitableview,Iphone,Cocoa Touch,Uitableview,我想以分组样式将数据库中的数据填充到表视图中。 可以更改记录的数量。(动态更改) 我试过了,但我只能在表视图中创建不同的带有标题的部分 例如:我的数据库有5个字段名称、地址、联系人、工资、技术 所以我想把name字段值放在节的头中,我成功地做到了 但当我试图填充该部分下的其他四个字段值时,它将只填充1个部分 第二个问题是,当我在屏幕上上下滚动时,值就会错位,这意味着会随机改变它们的位置。请确保正确设置了numberOfSectionsInTableView和numberOfRowsInSecti
第二个问题是,当我在屏幕上上下滚动时,值就会错位,这意味着会随机改变它们的位置。请确保正确设置了numberOfSectionsInTableView和numberOfRowsInSection。此外,还需要对cellForRowAtIndexPath进行编码,以标识节和每个节中的行。如果您需要一个完整的示例,请发布您现在用于该表视图的代码,我可以修改它以满足您的需要。确保您正确完成了numberOfSectionsInTableView和numberOfRowsInSection。此外,还需要对cellForRowAtIndexPath进行编码,以标识节和每个节中的行。如果您需要完整的示例,请发布您现在用于该TableView的代码,我可以对其进行修改以满足您的需要。首先在.h文件中导入table view委托,并确保遵循此格式
@interface CustomtableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource>
{
UITextField * username;
UIButton * submit;
}
@implementation CustomtableViewController
- (void)viewDidLoad
{
UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(10, 70, 300, 45)];
submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[submit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[submit setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled];
[submit setTitle:@"Login" forState:UIControlStateNormal];
[submit.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[submit setFrame:CGRectMake(10.0, 15.0, 280.0, 44.0)];
[newView addSubview:submit];
[self.tableView setTableFooterView:newView];
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//self.tableView.contentOffset = CGPointMake( 10, 320);
[self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ([indexPath section] == 0) {
username = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
username.adjustsFontSizeToFitWidth = YES;
username.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
username.placeholder = @"example@gmail.com";
username.keyboardType = UIKeyboardTypeEmailAddress;
username.returnKeyType = UIReturnKeyNext;
cell.textLabel.text = @"Username";
username.clearButtonMode = YES;
}
else {
username.placeholder = @"minimum 6 characters";
username.keyboardType = UIKeyboardTypeDefault;
username.returnKeyType = UIReturnKeyDone;
username.secureTextEntry = YES;
cell.textLabel.text = @"Password";
username.clearButtonMode = UITextFieldViewModeAlways;
}
username.backgroundColor = [UIColor whiteColor];
username.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
username.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
username.textAlignment = NSTextAlignmentLeft;
username.tag = 0;
username.clearButtonMode = UITextFieldViewModeAlways; // no clear 'x' button to the right
[username setEnabled: YES];
[cell.contentView addSubview: username];
}
// Configure the cell...
return cell;
}
所以,我这里的代码只是用来创建一个带有两个文本字段(用户名和密码)和一个登录按钮的登录页面。您可以根据需要修改我的代码。
干杯 首先在.h文件中导入表视图委托,并确保遵循此格式
@interface CustomtableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource>
{
UITextField * username;
UIButton * submit;
}
@implementation CustomtableViewController
- (void)viewDidLoad
{
UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(10, 70, 300, 45)];
submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[submit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[submit setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled];
[submit setTitle:@"Login" forState:UIControlStateNormal];
[submit.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[submit setFrame:CGRectMake(10.0, 15.0, 280.0, 44.0)];
[newView addSubview:submit];
[self.tableView setTableFooterView:newView];
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//self.tableView.contentOffset = CGPointMake( 10, 320);
[self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ([indexPath section] == 0) {
username = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
username.adjustsFontSizeToFitWidth = YES;
username.textColor = [UIColor blackColor];
if ([indexPath row] == 0) {
username.placeholder = @"example@gmail.com";
username.keyboardType = UIKeyboardTypeEmailAddress;
username.returnKeyType = UIReturnKeyNext;
cell.textLabel.text = @"Username";
username.clearButtonMode = YES;
}
else {
username.placeholder = @"minimum 6 characters";
username.keyboardType = UIKeyboardTypeDefault;
username.returnKeyType = UIReturnKeyDone;
username.secureTextEntry = YES;
cell.textLabel.text = @"Password";
username.clearButtonMode = UITextFieldViewModeAlways;
}
username.backgroundColor = [UIColor whiteColor];
username.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
username.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
username.textAlignment = NSTextAlignmentLeft;
username.tag = 0;
username.clearButtonMode = UITextFieldViewModeAlways; // no clear 'x' button to the right
[username setEnabled: YES];
[cell.contentView addSubview: username];
}
// Configure the cell...
return cell;
}
所以,我这里的代码只是用来创建一个带有两个文本字段(用户名和密码)和一个登录按钮的登录页面。您可以根据需要修改我的代码。
干杯 我想你很快就会收到一条评论,要求你看一些代码。特别是您用来填充表的代码。请与我们共享您的代码。特别是你的cellForRowAtIndexPath。我添加了代码……请修改rowforindex。我想你很快就会收到评论,要求你查看一些代码。特别是您用来填充表的代码。请与我们共享您的代码。特别是你的cellForRowAtIndexPath。我添加了代码…请修改rowforindex部分