请问 UI 表视图帮助?它不会显示背景,文本框或提交按钮 - iPhone SDK / Xcode



在实现以下代码时遇到困难:

设计视图:http://i53.tinypic.com/2hqe9lk.png

模拟器视图:http://i56.tinypic.com/2luw68j.png

它不显示背景、文本框,也不显示提交按钮:(它只显示表格。我做错了什么?

谢谢! !

视图的代码如下:

BooksTableViewController。m

//
//  BooksTableViewController.m
//  ORBooks
//
//  Created by Elisabeth Robson on 6/19/09.
//  Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import "BooksTableViewController.h"
#import "BookDetailViewController.h"
#import "ORBooksAppDelegate.h"
@implementation BooksTableViewController
@synthesize booksArray;
@synthesize bookDetailViewController;
@synthesize number;
/*
 - (id)initWithStyle:(UITableViewStyle)style {
 // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 if (self = [super initWithStyle:style]) {
 }
 return self;
 }
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
    [[self navigationItem] setBackBarButtonItem: newBackButton];    
    [newBackButton release];
    NSMutableArray *array = [[NSArray alloc] initWithObjects:@"sub1", @"sub2", nil];
    self.booksArray = array;
    [array release]; 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

/*
 - (void)viewWillAppear:(BOOL)animated {
 [super viewWillAppear:animated];
 }
 */
/*
 - (void)viewDidAppear:(BOOL)animated {
 [super viewDidAppear:animated];     
 }
/*
 - (void)viewWillDisappear:(BOOL)animated {
 [super viewWillDisappear:animated];
 }
 */
/*
 - (void)viewDidDisappear:(BOOL)animated {
 [super viewDidDisappear:animated];
 }
 */
/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;//[self.booksArray count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    // Set up the cell...
    NSUInteger row = [indexPath row];
    cell.text = [booksArray objectAtIndex:row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
    // [self.navigationController pushViewController:anotherViewController];
    // [anotherViewController release];
    NSInteger row = [indexPath row];
    if (self.bookDetailViewController == nil) {
        BookDetailViewController *aBookDetail = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:nil];
        self.bookDetailViewController = aBookDetail;
        [aBookDetail release];
    }
    //bookDetailViewController.title = [NSString stringWithFormat:@"%@", [booksArray objectAtIndex:row]];
    //ORBooksAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    //[delegate.booksNavController pushViewController:bookDetailViewController animated:YES];
    [self.navigationController pushViewController:bookDetailViewController animated:YES];
}

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
 }   
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }   
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

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

@end

BooksTableViewController.h

//
//  BooksTableViewController.h
//  ORBooks
//
//  Created by Elisabeth Robson on 6/19/09.
//  Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import <UIKit/UIKit.h>
@class BookDetailViewController;
// don't need to specify the delegate, datasource interfaces; UITableViewController gets those automatically
@interface BooksTableViewController : UITableViewController {
    IBOutlet UITextField *number;
    IBOutlet UITableView *booksTableView;
    NSMutableArray *booksArray;
    BookDetailViewController *bookDetailViewController;
}
- (IBAction)submit:(id)sender;
@property (nonatomic, retain) UITextField *number;
@property (nonatomic, retain) NSMutableArray *booksArray;
@property (nonatomic, retain) BookDetailViewController *bookDetailViewController;
@end

你必须在头文件中将UITableViewController更改为UIViewController。你要做的是将所有内容添加到tableview。相反,你必须将tableview添加到UIViewController, UITextfield和UIButton也是如此。

最新更新