Very basic table view but getting errors
trying to write this code since 2 days now, but i keep getting error, it would be nice if anyone could sort this out, thanks.
Basically its the same thing i doing from the tutorial on youtube.
awaiting a reply
#import "BooksTableViewController.h"
#import "BooksDetailViewController.h"
#import "MYbooksAppDelegate.h"
@implementation BooksTableViewContr开发者_开发问答oller
@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
Besides you didn't give us the exact error you're trying to close there's at least one warning I would give :)
[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identity]
This is deprecated code. You should rather use
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity]
if you're using OS 3.x (what I'm assuming).
精彩评论