好的,所以我正在编写一个 iPhone 应用程序,并将数据加载到分组表视图中,我创建了一个数据模型:
DataModel.m
#import "GeometryDataModel.h"
@implementation GeometryDataModel
@synthesize titleGeo =_titleGeo;
-(id)initWithTitleGeo:(NSString *)titleGeo
{
if ((self = [super init])) {
self.titleGeo = titleGeo;
}
return self;
}@end
然后我继续写数据表……
DataTable.m
#import "GeometryTableData.h"
#import "GeometryDataModel.h"
@implementation GeometryTableData
@synthesize dataGeo = _dataGeo;
@synthesize thumbImageGeo = _thumbImageGeo;
- (id)initWithTitleGeo:(NSString *)titleGeo thumbImageGeo:(UIImage *)thumbImageGeo {
if ((self = [super init]))
{
self.dataGeo = [[GeometryDataModel alloc] initWithTitleGeo:titleGeo];
self.thumbImageGeo = _thumbImageGeo;
}
return self;
}
@end
然后我创建了一个视图控制器来设置它
ViewController.m
#import "GeometryViewController.h"
#import "GeometryTableData.h"
#import "GeometryDataModel.h"
@interface GeometryViewController ()
@end
@implementation GeometryViewController
@synthesize geoCalculatorList = _geoCalculatorList;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#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
{
return _geoCalculatorList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *geoCell = [tableView dequeueReusableCellWithIdentifier:@"Geometry"];
GeometryTableData *geoTableStuff = [self.geoCalculatorList objectAtIndex:indexPath.row];
geoCell.textLabel.text = geoTableStuff.dataGeo.titleGeo;
geoCell.imageView.image = geoTableStuff.thumbImageGeo;
return geoCell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
最后,在 AppDelegate.m 文件中,我将它实现到表中:
sectionOne = [[TableData alloc] initWithTitle:@"A cell" thumbImage:[UIImage
imageNamed:@"none.png"]];
sectionTwo = [[TableData alloc] initWithTitle:@"Another separated cell" thumbImage:[UIImage
imageNamed:@"none.png"]];
NSMutableArray *TableData = [NSMutableArray arrayWithObjects:sectionOne,sectionTwo, nil];
UITabBarController * tabController = (UITabBarController *) self.window.rootViewController;
ViewController * algebraController = [tabController.viewControllers objectAtIndex:0];
Controller.calculatorList = TableData;
我的问题是,我将如何在分组表视图中创建部分,比如使用我当前的系统将“sectionOne”和“sectionTwo”放入表的不同部分?
谢谢!!!