0

我是 xcode 的新手,所以我在这里学习,我可能完全错了,但这是我的场景。我有一个打开视图控制器的故事板,带有一个转到导航控制器的按钮,这使用表视图从 mysql 数据库加载我的娱乐列表(这工作正常)它显示的表视图中的一个项目转到详细信息视图,但什么也没发生,调试器中没有错误。我做错了什么或者我做错了什么。我认为这个问题与 ENTERTAILMENTLISTING.M 中的 didSelectRowAtIndexPath 内容所在的部分有关,我已经包含了到目前为止的所有内容。

故事板 在此处输入图像描述

APPDELEGATE.H

//
//  AppDelegate.h


#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

APPDELEGATE.M

//
//  AppDelegate.m


#import "AppDelegate.h"


@implementation AppDelegate





- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

娱乐列表.H

//
//  EntertainmentListingViewController.h


#import <UIKit/UIKit.h>

@interface EntertainmentListingViewController : UIViewController{

    IBOutlet UITableView *mainTableView;
    NSArray *events;
    NSMutableData *data;


}


@end

娱乐列表.M

//
//  EntertainmentListingViewController.m


#import "EntertainmentListingViewController.h"
#import "EntertainmentDetailsViewController.h"

@interface EntertainmentListingViewController ()

@end

@implementation EntertainmentListingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // VIEW TITLE
    self.title = @"Entertainment";

    // SHOW NETWORK ACTIVITY INDICATOR
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    //GET DATA URL
    NSURL *url = [NSURL URLWithString:@"http://mydomain.com/myfile.php"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

//START CODE FOR TALBE VIEW

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    data = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
    [data appendData:theData];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //PROCESS JSON DATA HERE
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    events = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    [mainTableView reloadData];

}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    // WASNT ABLE TO CONNECT INTERNET THROW ERROR

    UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Connection To The Internet Is Available" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [errorView show];
    // TURN OFF NETWORk ACTIVITY INDICATOR
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}


- (int) numberOfSectionsInTableView: (UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;

}

- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [events count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)IndexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];

    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:@"MainCell"];



    }



    NSURL *url = [NSURL URLWithString: [[events objectAtIndex:IndexPath.row] objectForKey:@"eImg"]];
    NSData *idata = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:idata];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
    cell.imageView.image = imgView.image;


    cell.textLabel.text = [[events objectAtIndex:IndexPath.row] objectForKey:@"eName"];
    cell.detailTextLabel.text = [[events objectAtIndex:IndexPath.row] objectForKey:@"date_string"];
    return cell;
}





-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    EntertainmentDetailsViewController *entertainmentdetailsViewController = [[EntertainmentDetailsViewController alloc]
    initWithNibName:@"EntertainmentDetailsViewController" bundle:nil];
    entertainmentdetailsViewController.title = [[events objectAtIndex:indexPath.row] objectForKey:@"eName"];
    entertainmentdetailsViewController.entertainmentArticle = [events objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:entertainmentdetailsViewController animated:YES];
    // NOTHING HAPPENING HAS TO DO WITH THIS AREA I THINK
    NSLog(@"Navigation Cnntroller %@",self.navigationController);
    NSLog(@"Events COntroller %@", entertainmentdetailsViewController);

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

娱乐细节.H

//
//  EntertainmentDetailsViewController.h


#import <UIKit/UIKit.h>

@interface EntertainmentDetailsViewController : UIViewController{

    NSDictionary *entertainmentArticle;

    IBOutlet UILabel *titleLabel;
    IBOutlet UILabel *timeLabel;
    IBOutlet UITextView *descTextView;
}

@property (nonatomic, copy) NSDictionary *entertainmentArticle;

@end

娱乐细节.M

//
//  EntertainmentDetailsViewController.m


#import "EntertainmentDetailsViewController.h"

@interface EntertainmentDetailsViewController ()

@end

@implementation EntertainmentDetailsViewController
@synthesize entertainmentArticle;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    titleLabel.text = [entertainmentArticle objectForKey:@"eName"];
    timeLabel.text = [entertainmentArticle objectForKey:@"date_string"];
    descTextView.text = [entertainmentArticle objectForKey:@"eDetails"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

3 回答 3

2

您忘记了委托和数据源。如果你使用 uitableviewcontroller,所有的都连接起来,如果你将 tableview 拖到 uiviewcontroller 你必须做几件事:

编辑这一行:

@interface EntertainmentListingViewController : UIViewController  <UITableViewDataSource, UITableViewDelegate>

ctrl+将表格拖到视图控制器下方的黄色框。设置为委托,再次拖动并设置为源。

于 2013-09-18T11:49:35.673 回答
0

将委托分配为 self 并放置断点以查找控制是否到达委托方法

于 2013-09-18T11:44:48.450 回答
0

这里 EntertainmentListingViewController 是 UIViewController 的子类@interface EntertainmentListingViewController : UIViewController。所以你不能使用[self.navigationController pushViewController:entertainmentdetailsViewController animated:YES];API​​。您可以使用[self presentModalViewController:entertainmentdetailsViewController animated:YES];

于 2013-09-18T11:51:03.353 回答