非常基本的表视图,但收到错误

时间:2010-05-16 16:29:50

标签: iphone uitableview

现在尝试编写此代码2天,但我一直都会收到错误,如果有人能解决这个问题会很好,谢谢。

基本上我在youtube上的教程中做了同样的事情。

等待回复

#import "BooksTableViewController.h"
#import "BooksDetailViewController.h"
#import "MYbooksAppDelegate.h"

@implementation BooksTableViewController
@synthesize BooksArray;
@synthesize BooksDetailViewController;

 - (void)viewDidLoad { 
 [super viewDidLoad];
 self.title = NSLocalizedString(@"XYZ",@"GOD is GREAT");

 NSMutableArray *array = [[NSArray alloc] initWithObjects:@"H1",@"2",@"3",nil];
 self.booksArray = array;
 [array release];

}

#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 [self.booksArray count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *identity = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identity] autorelease];
    }

    // Set up the cell...
 cell.textLabel.text = [booksArray objectAtIndex:indexPath.row];
 return cell;
}

// ...various boiler plate methods
@end

1 个答案:

答案 0 :(得分:0)

除此之外你没有告诉我们你要关闭的确切错误,至少有一个我会给出的警告:)

[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identity]

这是不推荐使用的代码。你应该使用

[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity]

如果您使用的是OS 3.x(我假设的那样)。