Xcode新手, 我创建了一个分组表视图,每个部分包含不同数量的行,我现在不知道用数据填充单元格的最佳方法,然后在按下单元格时移动到下一个视图。 请帮忙。 谢谢
答案 0 :(得分:0)
您可以尝试这个基本教程,看看如何填充表格。 http://blog.webscale.co.in/?p=150
并且当按下单元格时执行操作,你基本上需要在didSelectRowAtIndexPath方法中执行类似的操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if( 0 == indexPath.row)
{
NSLog(@"first row selected");
if(patientView == nil)
patientView = [[PatientList alloc]init];
[self.navigationController pushViewController:patientView animated:YES];
}
这只是你想要做的一个非常基本的例子...玩这个会有助于你了解更多......
答案 1 :(得分:0)
**set in .h file**
@property(nonatomic, retain)NSArray *data;
@property(nonatomic, retain)NSArray *sections;
**in .m file view did load**
self.sections = [[NSArray alloc] initWithObjects:@"university",@"sabaragamuwa",@"Srilanka",nil];
self.data = [[NSArray alloc]initWithObjects:
[[NSArray alloc] initWithObjects:
@"CiS",
@"006",
@"07", nil],
[[NSArray alloc] initWithObjects:
@"cis",
@"006",
@"007", nil],
[[NSArray alloc] initWithObjects:
@"cis",
@"006",
@"07", nil],nil];
**addthoose**
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return [self.sections count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [self.sections objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [data count];}
**addalsooo**
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
// Configure the cell...
if (cell == nil){
// Create the cell.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
}
NSArray* dataArray = [data objectAtIndex:indexPath.section];
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:139.0/255.0 blue:69.0/255.0 alpha:1.0];
UIImage *cellImage = [UIImage imageNamed:@"oranimCellIco.png"];
cell.imageView.image = cellImage;
return cell;}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray* dataArray = [data objectAtIndex:indexPath.section];
NSString *catgory= [dataArray objectAtIndex:indexPath.row];
if(catgory==@"cis")
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Answer Set"
message:@"Answer set as Yes Or No"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
else if(catgory==@"006")
{
answerviewcon *vc1=[self.storyboard instantiateViewControllerWithIdentifier:@"answerviewcon"];
[self presentViewController:vc1 animated:YES completion:nil];
}