dimissModalViewControllerAnimated, заставляющая tableView быть полным экраном? - PullRequest
0 голосов
/ 16 июня 2011

У меня есть RootViewController с 2 табличными представлениями в качестве подпредставлений (созданных в IB), каждый из которых имеет свой собственный класс tableViewController (обрабатывает fetchRequests и т.1003 *

tableView 2 имеет кнопку в заголовке, которая представляет imagePickerController.Никаких проблем пока нет.

Проблема в том, что когда я закрываю окно imagePicker

 [self dismissModalViewControllerAnimated:YES];

TableView 2 становится полноэкранным, я пытался

[[self rootViewController] dismissModalViewControllerAnimated:YES]

Ничего не происходит вообще.Он прикрепляется к средству выбора изображений.

Я подозреваю, что это происходит из-за того, что очень мало изображений создается программно.

Есть идеи?

Заранее спасибо.

DetartrateD

 -(IBAction)addImageTableAPressed {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];  
}

            RootViewController
             ||            ||
             ||            ||    
             \/            \/          addImageTableAPressed
  TableViewControlA  TableViewControlB --------------------->modelViewController

Для разрешения mananagedObjectContect .....

     - (void)viewDidLoad {...
 if(managedObjectContext == nil) 
{ 
    managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
    NSLog(@"After managedObjectContext: %@",  managedObjectContext);
}
   ...
  }

1 Ответ

0 голосов
/ 17 июня 2011

Как я упоминал в одном из моих комментариев, я бы предпочел иметь один контроллер представления, управляющий двумя представлениями таблицы.Определите UIView (rootView), включая 2 подпредставления (tableViewA и tableViewB).Представлением вашего RootViewController будет rootView, и этот контроллер должен быть источником данных и делегатом обоих табличных представлений.Код, который я приведу здесь, ни в коем случае не является полным и не оптимальным, но дает вам хорошее представление о том, что необходимо для реализации моего решения.

Например:

@interface RootViewController <UITableViewDelegate, UITableViewDataSource> {
    NSArray *dataArrayA;
    NSArray *dataArrayB;
    UITableView tableViewA;
    UITableView tableViewB;
    NSManagedObjectContext *context;
}

@property (nonatomic, retain) NSArray *dataArrayA;
@property (nonatomic, retain) NSArray *dataArrayB;

// in IB, link the dataSource and delegate outlets of both tables to RootViewController
@property (nonatomic, retain) IBOutlet UITableView tableViewA;
@property (nonatomic, retain) IBOutlet UITableView tableViewB;

// this property will allow you to pass the MOC to the RootViewController from 
// the parent view controller, instead of accessing the app delegate from RootViewController
@property (nonatomic, retain) NSManagedObjectContext *context;

// ... etc.

@end



@implementation RootViewController

@synthesize dataArrayA;
@synthesize dataArrayB;
@synthesize tableViewA;
@synthesize tableViewB;
@synthesize context;

// initialize dataArrayA and dataArrayB
- (void)viewDidLoad {
    [super viewDidLoad];

    NSError *error = nil;

    // initialize and configure your fetch request for data going into tableViewA
    NSFetchRequest fetchRequestA = [[NSFetchRequest alloc] init];

    // configure the entity, sort descriptors, predicate, etc.
    // ...

    // perform the fetch
    self.dataArrayA = [context executeFetchRequest:fetchRequestA error:&error];

    // do the same for the data going into tableViewB - the code is very similar, you
    // could factor it out in a private method instead of duplicating it here
    // NSFetchRequest fetchRequestB = [[NSFetchRequest alloc] init]; 

    // omitting the details ... etc.

    self.dataArrayB = [context executeFetchRequest:fetchRequestB error:&error];

    // release objects you don't need anymore, according to memory management rules
    [fetchRequestA release];
    [fetchRequestB release];
}


// Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // if you have a different number of sections in tableViewA and tableViewB
/*
    if (tableView == tableViewA) {
        return ??;
    } else {
        return ??
    }
*/

    // otherwise, if both table views contain one section
    return 1;
}

// Customize the number of rows in each table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == tableViewA) {
        return [dataArrayA count];
    } else {
        return [dataArrayB count];
    }
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;

    if (tableView == tableViewA) {
        // get the data for the current row in tableViewA
        id objectA = [dataArrayA objectAtIndex:indexPath.row];

        // configure the cell for tableViewA
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierA];

        // etc...
    } else {
        // get the data for the current row in tableViewB
        id objectB = [dataArrayB objectAtIndex:indexPath.row];

        // configure the cell for tableViewB
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierB];
        // etc...
    }
    return cell;
}

// And so on, the same idea applies for the other UITableViewDelegate you would need to 
// implement...


- (void)dealloc {
    [dataArrayA release];
    [dataArrayB release];
    [tableViewA release];
    [tableViewB release];
    [context release];

    // etc...

    [super dealloc];
}

@end

Я надеюсь, что выВы найдете это полезным.

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