07-18-2011, 05:13 AM
#1 (permalink )
Registered Member
Join Date: Jul 2011
Posts: 7
Custom cells not working
Hi, I have a table view with custom cells build using this tutorial :
The Pragmatic Studio | Bonus Track
And now I have 2 issues.
First and main, nothing happens when I tap on a row, I mean its highlighted but not opening new view
Second: How can I make these custom cells to open individual views displaying text and button to listen to audio. And is it possible that my existing tab bar will be still visible?
Thank you
This is my table.h
Code:
@class ChapterTableCell;
@interface AllChaptersTableViewController : UITableViewController {
NSArray *chapters;
IBOutlet ChapterTableCell *chapterTableCell;
}
@property (nonatomic, retain) NSArray *chapters;
@property (nonatomic, retain) ChapterTableCell *chapterTableCell;
@end
and this is my table.m file
Code:
#import "AllChaptersTableViewController.h"
#import "AllChaptersTableViewController.h"
#import "speaking_palAppDelegate.h"
#import "Chapter.h"
#import "ChapterTableCell.h"
@implementation AllChaptersTableViewController
@synthesize chapters, chapterTableCell;
- (void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
self.title = @"Chapters";
Chapter *one = [[Chapter alloc]
initWithName:@"1"
imageName:@"Button_1.png"];
Chapter *two = [[Chapter alloc]
initWithName:@"2"
imageName:@"Button_2.png"];
Chapter *three = [[Chapter alloc]
initWithName:@"3"
imageName:@"Button_3.png"];
Chapter *four = [[Chapter alloc]
initWithName:@"4"
imageName:@"Button_4.png"];
Chapter *five = [[Chapter alloc]
initWithName:@"5"
imageName:@"Button_5.png"];
Chapter *six = [[Chapter alloc]
initWithName:@"6"
imageName:@"Button_6.png"];
Chapter *seven = [[Chapter alloc]
initWithName:@"7"
imageName:@"Button_7.png"];
Chapter *eight = [[Chapter alloc]
initWithName:@"8"
imageName:@"Button_8.png"];
Chapter *nine = [[Chapter alloc]
initWithName:@"9"
imageName:@"Button_9.png"];
Chapter *ten = [[Chapter alloc]
initWithName:@"10"
imageName:@"Button_10.png"];
Chapter *eleven = [[Chapter alloc]
initWithName:@"11"
imageName:@"Button_11.png"];
Chapter *twelve = [[Chapter alloc]
initWithName:@"12"
imageName:@"Button_12.png"];
Chapter *thirteen = [[Chapter alloc]
initWithName:@"13"
imageName:@"Button_13.png"];
Chapter *fourteen = [[Chapter alloc]
initWithName:@"14"
imageName:@"Button_14.png"];
Chapter *fifteen = [[Chapter alloc]
initWithName:@"15"
imageName:@"Button_15.png"];
Chapter *sixteen = [[Chapter alloc]
initWithName:@"16"
imageName:@"Button_16.png"];
Chapter *seventeen = [[Chapter alloc]
initWithName:@"17"
imageName:@"Button_17.png"];
NSArray *exampleData =
[[NSArray alloc] initWithObjects:one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, nil];
self.chapters = exampleData;
[one release];
[two release];
[three release];
[four release];
[five release];
[six release];
[seven release];
[eight release];
[nine release];
[ten release];
[eleven release];
[twelve release];
[thirteen release];
[fourteen release];
[fifteen release];
[sixteen release];
[seventeen release];
[exampleData release];
[super viewDidLoad];
}
#pragma mark -
#pragma mark Memory methods
- (void)dealloc {
[chapters release];
[chapterTableCell release];
[super dealloc];
}
#pragma mark -
#pragma mark Table View methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.chapters count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ChapterCellId";
ChapterTableCell *cell =
(ChapterTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ChapterTableCell" owner:self options:nil];
cell = chapterTableCell;
}
Chapter *chapter = [chapters objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[chapter imageName]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 73;
}
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
@end
and this is cell.m
Code:
#import "ChapterTableCell.h"
#import "Chapter.h"
@implementation ChapterTableCell
@synthesize nameLabel, imageView;
- (void)dealloc {
[nameLabel release];
[imageView release];
[super dealloc];
}
@end
and cell h
Code:
@interface ChapterTableCell : UITableViewCell {
IBOutlet UILabel *nameLabel;
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UIImageView *imageView;
@end
Last edited by oleger; 07-18-2011 at 05:49 AM .
Reason: code
07-18-2011, 08:06 AM
#2 (permalink )
Registered Member
Join Date: Dec 2010
Posts: 39
Quote:
Originally Posted by
oleger
Hi, I have a table view with custom cells build using this tutorial :
The Pragmatic Studio | Bonus Track
And now I have 2 issues.
First and main, nothing happens when I tap on a row, I mean its highlighted but not opening new view
Second: How can I make these custom cells to open individual views displaying text and button to listen to audio. And is it possible that my existing tab bar will be still visible?
Thank you
This is my table.h
Code:
@class ChapterTableCell;
@interface AllChaptersTableViewController : UITableViewController {
NSArray *chapters;
IBOutlet ChapterTableCell *chapterTableCell;
}
@property (nonatomic, retain) NSArray *chapters;
@property (nonatomic, retain) ChapterTableCell *chapterTableCell;
@end
and this is my table.m file
Code:
#import "AllChaptersTableViewController.h"
#import "AllChaptersTableViewController.h"
#import "speaking_palAppDelegate.h"
#import "Chapter.h"
#import "ChapterTableCell.h"
@implementation AllChaptersTableViewController
@synthesize chapters, chapterTableCell;
- (void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
self.title = @"Chapters";
Chapter *one = [[Chapter alloc]
initWithName:@"1"
imageName:@"Button_1.png"];
Chapter *two = [[Chapter alloc]
initWithName:@"2"
imageName:@"Button_2.png"];
Chapter *three = [[Chapter alloc]
initWithName:@"3"
imageName:@"Button_3.png"];
Chapter *four = [[Chapter alloc]
initWithName:@"4"
imageName:@"Button_4.png"];
Chapter *five = [[Chapter alloc]
initWithName:@"5"
imageName:@"Button_5.png"];
Chapter *six = [[Chapter alloc]
initWithName:@"6"
imageName:@"Button_6.png"];
Chapter *seven = [[Chapter alloc]
initWithName:@"7"
imageName:@"Button_7.png"];
Chapter *eight = [[Chapter alloc]
initWithName:@"8"
imageName:@"Button_8.png"];
Chapter *nine = [[Chapter alloc]
initWithName:@"9"
imageName:@"Button_9.png"];
Chapter *ten = [[Chapter alloc]
initWithName:@"10"
imageName:@"Button_10.png"];
Chapter *eleven = [[Chapter alloc]
initWithName:@"11"
imageName:@"Button_11.png"];
Chapter *twelve = [[Chapter alloc]
initWithName:@"12"
imageName:@"Button_12.png"];
Chapter *thirteen = [[Chapter alloc]
initWithName:@"13"
imageName:@"Button_13.png"];
Chapter *fourteen = [[Chapter alloc]
initWithName:@"14"
imageName:@"Button_14.png"];
Chapter *fifteen = [[Chapter alloc]
initWithName:@"15"
imageName:@"Button_15.png"];
Chapter *sixteen = [[Chapter alloc]
initWithName:@"16"
imageName:@"Button_16.png"];
Chapter *seventeen = [[Chapter alloc]
initWithName:@"17"
imageName:@"Button_17.png"];
NSArray *exampleData =
[[NSArray alloc] initWithObjects:one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, nil];
self.chapters = exampleData;
[one release];
[two release];
[three release];
[four release];
[five release];
[six release];
[seven release];
[eight release];
[nine release];
[ten release];
[eleven release];
[twelve release];
[thirteen release];
[fourteen release];
[fifteen release];
[sixteen release];
[seventeen release];
[exampleData release];
[super viewDidLoad];
}
#pragma mark -
#pragma mark Memory methods
- (void)dealloc {
[chapters release];
[chapterTableCell release];
[super dealloc];
}
#pragma mark -
#pragma mark Table View methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.chapters count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ChapterCellId";
ChapterTableCell *cell =
(ChapterTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ChapterTableCell" owner:self options:nil];
cell = chapterTableCell;
}
Chapter *chapter = [chapters objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[chapter imageName]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 73;
}
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
@end
and this is cell.m
Code:
#import "ChapterTableCell.h"
#import "Chapter.h"
@implementation ChapterTableCell
@synthesize nameLabel, imageView;
- (void)dealloc {
[nameLabel release];
[imageView release];
[super dealloc];
}
@end
and cell h
Code:
@interface ChapterTableCell : UITableViewCell {
IBOutlet UILabel *nameLabel;
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UIImageView *imageView;
@end
u can use didSelectRowAtIndexPath method......then u can write navigation logic in in that method
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 412
15 members and 397 guests
blasterbr , buggen , Clouds , dre , EvilElf , HemiMG , jeroenkeij , jimmyon122 , jonathandeknudt , LEARN2MAKE , Mah6447 , n00b , nyoe , pungs , stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,901
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt