iPhone несколько элементов управления UITableView на одном View - PullRequest
0 голосов
/ 13 декабря 2010

У меня небольшая проблема с использованием более 1 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 признателен.

Спасибо всем.

1 Ответ

0 голосов
/ 13 декабря 2010

Ваша единственная определяющая itemsTable в вашем заголовке, попробуйте определить другую таблицу, и в вашем cellForRowAtIndexPath попробуйте это:

if(itemsTable1){
    /* stuff for first table  */
} else {
    /* stuff for second table  */
}

И сделать то же самое для каждого делегата UITableVIew

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...