Переход от табличного представления к различным подробным представлениям в xcode - PullRequest
0 голосов
/ 21 мая 2011

Я начинающий программист.И у меня возник вопрос.В настоящее время в моем приложении есть табличное представление.В ней три строки: история, теория и прикладное использование.Я хотел бы, чтобы каждый пошел в различный подробный вид.Однако каждый из них нажимает только на один из подробных видов.

Я думаю, что проблема в

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"Magnets_AU_Aubrey" bundle:[

Пожалуйста, помогите любому.Три XIB - это Магниты_Аври, Магниты_История_Обрей и Магниты_Теория_Обрей

#import "DisclosureButtonController.h"
#import "NavAppDelegate.h"
#import "DisclosureDetailController.h"
#import "DetailViewController.h"

@implementation DisclosureButtonController
@synthesize list;

- (void)viewDidLoad {
    NSArray *array = [[NSArray alloc] initWithObjects:@"History", @"Theory", @"Applied Use", nil];
    self.list = array;
    [array release];
    [super viewDidLoad];
}

- (void)viewDidUnload {
    self.list = nil;
    [childController release], childController = nil;
}

- (void)dealloc {
    [list release];
    [childController release];
    [super dealloc];
}

#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
    return [list count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString * DisclosureButtonCellIdentifier =
    @"DisclosureButtonCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             DisclosureButtonCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
                 initWithStyle:UITableViewCellStyleDefault
                 reuseIdentifier:DisclosureButtonCellIdentifier] autorelease];
    }
    NSUInteger row = [indexPath row];
    NSString *rowString = [list objectAtIndex:row];
    cell.textLabel.text = rowString;
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    [rowString release];
    return cell;
}

#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"Magnets_AU_Aubrey" bundle:[
                                                                                                          NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];
    [dvController release];
     dvController = nil;
     }



- (void)tableView:(UITableView *)tableView

accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    if (childController == nil) {
        childController = [[DisclosureDetailController alloc] initWithNibName:@"MagnetsAubreyCreditsDisclosureDetail" bundle:nil];
    }
    childController.title = @"Disclosure Button Pressed";
    NSUInteger row = [indexPath row];
    NSString *selectedMovie = [list objectAtIndex:row];
    NSString *detailMessage = [[NSString alloc]
                               initWithFormat:@"School",selectedMovie];
    childController.message = detailMessage;
    childController.title = selectedMovie;
    [detailMessage release];
    [self.navigationController pushViewController:childController animated:YES];
}

@end

1 Ответ

0 голосов
/ 21 мая 2011
NSArray *array = [[NSArray alloc] initWithObjects:@"History", @"Theory", @"Applied Use", nil];

Теперь сделайте то же самое для XIBS. Создайте массив и заполните его именами XIB. Затем в didSelectRowAtIndexPath для получения правильного имени XIB примените ту же логику, что и в cellForRowAtIndexPath для получения текста ячейки.

...