我有一個小問題,在視圖上使用多個UITableView。iPhone多個UITableView控件在一個視圖
這裏就是我(在這裏和其他地方使用例子等),迄今所做的:
創建一個類爲每個表。每個類是非常基本的:
.H:
@interface ConstructionDocumentsJobTable : UITableViewController <UITableViewDataSource, UITableViewDelegate> {
NSMutableArray *tableItems;
IBOutlet UITableView *itemsTable;
NSInteger recordSelected;
id <JobTableSelectionDelegate> tableSelectDelegate;
}
@property (nonatomic, retain) NSMutableArray *tableItems;
@property (nonatomic, assign) id <JobTableSelectionDelegate> tableSelectDelegate;
@end
.M:
@implementation ConstructionDocumentsJobTable
@synthesize tableItems, tableSelectDelegate;
#pragma mark -
#pragma mark View Life Cycle
-(void) loadView
{
}
-(void) dealloc
{
[tableItems release];
[super dealloc];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableItems count];
}
// 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];
}
cell.textLabel.text = [tableItems objectAtIndex:indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//pass the tap value back to the delegate
}
兩者是完全一致的,保存的名稱。
當我對第一個進行調用時,它在視圖控制器的ViewDidLoad方法中調用。這是非常基本的:
NSMutableArray *tableItems = [[NSMutableArray alloc] initWithCapacity:intMax];
//strDocumentType is set elsewhere and loaded here
if(strDocumentType == @"typea"){
[tableItems addObject:@"Type A - Value 1"];
[tableItems addObject:@"Type A - Value 2"];
}
else {
[tableItems addObject:@"Type B - Value 1"];
}
if(jobTableController == nil){
jobTableController = [[ConstructionDocumentsJobTable alloc] init];
[jobTableController loadView];
jobTableController.tableItems = tableItems;
jobTableController.tableSelectDelegate = self;
}
[tableJobList setDataSource:jobTableController];
[tableJobList setDelegate:jobTableController];
jobTableController.view = jobTableController.tableView;
第二個表格是在第一個表格中的單元格被選中時構建的。因此,在第一個表格選擇方法中,委託從父控制器被回調,然後執行以下代碼:
NSMutableArray * tableTypeItems = [[NSMutableArray alloc] initWithCapacity:100];
if(tableSelect == @"plumbing"){
[tableTypeItems addObject:@"Something"];
[tableTypeItems addObject:@"Other"];
}
if(typeTableController == nil){
typeTableController = [[ConstructionDocumentsTypeTable alloc] init];
[typeTableController loadView];
typeTableController.tableItems = tableTypeItems;
typeTableController.tableSelectDelegate = self;
}
[tableTypeList setDataSource:typeTableController];
[tableTypeList setDelegate:typeTableController];
typeTableController.view = typeTableController.tableView;
[typeTableController.tableView reloadData];
//Code to move the first table off the screen and move this one into view goes here
我一直堅持這幾天,我真的需要做到這一點!
我確定這是一件簡單的事情。
任何幫助你們可以傳遞的將是HUGELY讚賞。
謝謝大家。
重複的問題:嘗試此http:/ /stackoverflow.com/a/11789681/846372 – Soniya 2012-08-03 05:20:00