I am trying to create a custom cell through the following code below in my TableView. I am 100% new to Objective C and Iphone development so I am far away from experienced.
On the following code: cell.label1 = [[UILabel alloc] initWithFrame:labelFrame]; it says (Property 'label1' not found on object of type 'UITableViewCell':
What have I missed? All the relevant code can be found below. Thanx for all the help / beginner
BookmarksViewController.h
@interface BookmarksViewController : UITableViewController <UIAlertViewDelegate>
{
NSMutableArray *items;
UILabel *label1;
UILabel *label2;
UILabel *label3;
}
@property (nonatomic, retain) NSMutableArray *items;
@property (nonatomic, retain) UILabel *label1;
@property (nonatomic, retain) UILabel *label2;
@property (nonatomic, retain) UILabel *label3;
- (NSMutableArray*) getStoredItems;
- (void) clearItems;
- (void) removeItemWithId:(int)itemId;
@end
BookmarksViewController.m
#import "BookmarksViewController.h"
@interface BookmarksViewController ()
@end
@implementation BookmarksViewController
@synthesize items;
@synthesize label1 = _label1;
@synthesize label2 = _label2;
@synthesize label3 = _label3;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BookmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
CGRect labelFrame = cell.bounds;
labelFrame.size.height= labelFrame.size.height * 0.5;
cell.label1 = [[UILabel alloc] initWithFrame:labelFrame];
}
Bookmark *item = [self.items objectAtIndex:indexPath.row];
NSArray *chunks = [item.name componentsSeparatedByString: @","];
NSString *name;
NSString *book;
NSString *chapter;
if ([chunks count] > 0)
{
name = [chunks objectAtIndex:0];
if ([chunks count] > 1)
{
book = [chunks objectAtIndex:1];
if ([chunks count] > 2)
{
chapter = [chunks objectAtIndex:2];
}
}
}
cell.label1.text = name;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70; // height of tableView Cell
}