UITableView didSelectRowAtIndex TabBar и Subview не работает - PullRequest
0 голосов
/ 27 января 2012

Я рву волосы над этой гочей и провожу пару недель.XCode 4.2 со сборкой нацелен на IOS4, поэтому я имею дело с файлами .XIB.

Я пишу приложение для iphone с двумя вкладками, предоставляемыми через tabBar, 1) мои исполнители, 2) все исполнители.У каждой из вкладок есть UITableview, который является модным.Существует также подробный вид, который отображает больше информации о работе.(Есть также дисплей HUD, который является копией MBProgressHUD Matej Bukovinski)

Когда я вызываю didSelectRowAtIndexPath, я не могу вызвать подробный вид, чтобы спасти мою жизнь.(Он срабатывает правильно.

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

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

- Роб

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
    UINavigationController *navigationController;

}
@property (strong, nonatomic) UINavigationController *navigationController; 
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end

AppDelegate.m

#import "AppDelegate.h"
#import "MyArtistsViewController.h"
#import "SecondViewController.h"
#import "TicketDetailView.h"
#import "viewTest.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize navigationController =_navigationController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //Test on navigationController
    //navigationController = [[UINavigationController alloc] initWithRootViewController:MyArtistsViewController];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil];
    //UINavigationController *viewController1 = [[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil];

    //UIViewController *tvc = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil]; 
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];


    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];


    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

MyArtistsViewController.h

#include "MBProgressHUD.h"
#import "TicketViewController.h"
@interface MyArtistsViewController : UIViewController
<MPMediaPickerControllerDelegate, UITableViewDelegate,CLLocationManagerDelegate,  
UITableViewDataSource, MBProgressHUDDelegate> 
{
    IBOutlet UITableView *tblEvents; 
    MBProgressHUD *HUD;

}
@property (nonatomic, retain) TicketViewController *detailViewController;
@property (nonatomic, retain) IBOutlet UITableView *tblEvents; 
@property (nonatomic, retain) IBOutlet CLLocationManager *locationManager; 
@property (nonatomic, retain) NSString *eventID, *artistName; 
@end

MyArtistsViewController.m

#import "MyArtistsViewController.h"
@synthesize ticketViewController; 
@synthesize detailViewController; 
@synthesize tblEvents;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Master", @"Master");
    }
    return self;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.detailViewController) {
        self.detailViewController = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil];
    }
    [self.navigationController pushViewController:self.detailViewController animated:YES];
}
- (void)viewDidLoad
//Create the Spinner or (HUD, Heads Up Display)  to let the User know whats going on. 
    HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD];
    [self.navigationController.view addSubview:HUD];

    HUD.delegate = self;
    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"Wow you read this far!";
    HUD.square = YES;
    [HUD show:YES]; 

    // Does a bunch of stuff

    [HUD show:NO];

1 Ответ

1 голос
/ 27 января 2012

В AppDelegate.m вы должны добавить UINavigationController в контроллер представления панели вкладок вместо обычного контроллера представления:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //Test on navigationController
    //navigationController = [[UINavigationController alloc] initWithRootViewController:MyArtistsViewController];
    // Override point for customization after application launch.
    UIViewController *artistsVC = [[[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil] autorelease]; //remove autorelease if ARC support
    UINavigationController *viewController1 = [[[UINavigationController alloc] initWithRootViewController:artistsVC] autorelease];

    //UIViewController *tvc = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil]; 
    //self.navigationController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];


    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];


    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
...