1

我正在创建一个两级表视图。第二个视图应该在我的 viewDidLoad 方法中包含我在下面列出的电影列表,但它没有显示。(你可以看到我附加的屏幕截图)有谁知道我可以查看哪个文件以了解它的原因不显示?下面的代码来自我的 DisclosureButtonController.m 文件,该文件用于在我点击第一级屏幕上的 Disclosure Buttons 实例后显示此信息。

问候,

启动的第一个屏幕 应该显示从我的 viewDidLoad 方法中列出的电影的屏幕

#import "LWWDisclosureButtonController.h"
#import "LWWAppDelegate.h"
#import "LWWDisclosureDetailController.h"

@interface LWWDisclosureButtonController ()
@property (strong, nonatomic) LWWDisclosureDetailController *childController;
@end

@implementation LWWDisclosureButtonController

@synthesize list;
@synthesize childController;

//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//if (self) {
    // Custom initialization
//}
//return self;
//}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"Toy Story", @"A Bug's Life", @"Toy     Story 2", @"Monsters, Inc.", @"Finding Nemo", @"The Incredibles", @"Cars", @"Ratatouille",    @"WALL-E", @"Up", @"Toy Story 3", @"Cars 2", @"Brave", nil];
 self.list = array;
// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
[super viewDidUnload];
self.list = nil;
self.childController = nil;
// Release any retained subviews of the main view.
}

#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];
}
NSUInteger row = [indexPath row];
NSString *rowString = [list objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;

}

#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hey, boss do you see the   disclosure button?" message:@"If you're trying to drill down, touch that instead mate!" delegate:nil cancelButtonTitle:@"Won't happen again" otherButtonTitles:nil];
[alert show];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:   (NSIndexPath *)indexPath
{
if (childController == nil)
{
    childController = [[LWWDisclosureDetailController   alloc]initWithNibName:@"LWWDisclosureDetail" bundle:nil];
}
childController.title = @"Disclosure Button Pressed";
NSUInteger row = [indexPath row];
NSString *selectedMovie = [list objectAtIndex:row];
NSString *detailMessage = [[NSString alloc]initWithFormat:@"You pressed the disclosure  button for %@.", selectedMovie];
childController.message = detailMessage;
childController.title = selectedMovie;
[self.navigationController pushViewController:childController animated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@结尾

4

2 回答 2

0

称呼:

[self.tableView reloadData]; (put in place of self.tableView the var or property connected to the tableView)

之后:

self.list = array;

viewDidLoad 方法中的代码行

并放一个

NSLog(@"number of rows: %d", [self.list count]);

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
     return [list count];//
  }

检查它是否不为零。

于 2012-07-29T21:47:53.187 回答
0

为什么不使用 VC 而不是在 VC 加载后启动阵列?尝试覆盖 init 方法。

- (id) init {
    if((self == [super init])) {
        //load your array here and set
    }
    return self;
}

这样,在旧设备上,您不必等待视图加载后才能看到数组。但是,这是我的偏好。我喜欢重写 init 方法并创建自己的方法。

另外,由于我的 SDK 上的一些奇怪的原因,我必须使用 NSMutableArray 而不是 NSArray ,否则它将无法工作。也许你有同样的问题?

另外,我注意到 NSString *selectedMovie。不要只使用“行”,而是使用 getter indexPath.row。

希望这些建议有所帮助!

于 2012-07-29T21:40:42.037 回答