10-13-2009, 06:14 PM
#1 (permalink )
Registered Member
Join Date: Sep 2009
Location: United States
Posts: 73
Table View Cell Problem/ Question
Hey everyone,
I'm working on an app that has a table view in it. I had no problem using it and navigation was working great but I decided that it would look more professional if I had the Name and than a mini summary of the next view when you tapped on the cell. I designed my custom cell but the problem I am having is loading up a new view when a particular cell is tapped. I used isEqual to the name of one of the arrays when I used a regular table view but now I get an error saying too many arguments to function 'isEqual'
Here is what my code looks like
Code:
NSString *customCellContent[][2] = {
{@"Sample", @"blah blah"},
{@"Sample 2", @"blah blah"},
// and it keeps going
};
@implementation Sample
@synthesize tableContent, theCustomCell;
-(void) loadTestData {
// fill moviesArray with test data
for (int i=0; i< 10; i++) {
CustomCell *theCell = [[CustomCell alloc] init];
theCell.title = customCellContent[i][0];
theCell.summary = customCellContent[i][2];
[tableContent addObject: theCell];
[theCell release];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Sample";
tableContent = [[NSMutableArray alloc] init];
[self loadTestData];
}
// 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) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:NULL];
cell = theCustomCell;
}
// Set up the cell...
CustomCell *aCell = [tableContent objectAtIndex:indexPath.row];
UILabel *titleLabel = (UILabel*) [cell viewWithTag:1];
titleLabel.text = aCell.title;
UILabel *summaryLabel = (UILabel*) [cell viewWithTag:3];
summaryLabel.text = aCell.summary;
return cell;
}
//here is my problem
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableContent objectAtIndex:indexPath.row] isEqual:@"Sample", @"blah blah"])
{
SampleViewController *sample = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
[sample setTitle:@"Sections"];
ApptitutorAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.sampleNavController pushViewController:sample animated:YES];
}
}
Any help would be greatly appreciated!
Thanks!
iPhonig
10-13-2009, 06:32 PM
#2 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 52
if ([[tableContent objectAtIndex:indexPath.row] isEqual:@"Sample", @"blah blah"])
This is not the objective C way to send a message that takes two arguments. Did you define an IsEqual message in your CustomCell class? If so, then I would expect call to look like
[[tableContent objectAtIndex:indexPath.row] isEqual: @"Sample" secondArg: @"blah blah"];
Where secondArg would be replaced by whatever you called it.
10-13-2009, 06:54 PM
#3 (permalink )
Registered Member
Join Date: Sep 2009
Location: United States
Posts: 73
Quote:
Originally Posted by
Iphoneer
if ([[tableContent objectAtIndex:indexPath.row] isEqual:@"Sample", @"blah blah"])
This is not the objective C way to send a message that takes two arguments. Did you define an IsEqual message in your CustomCell class? If so, then I would expect call to look like
[[tableContent objectAtIndex:indexPath.row] isEqual: @"Sample" secondArg: @"blah blah"];
Where secondArg would be replaced by whatever you called it.
No I didn't how do I do that?
10-13-2009, 09:43 PM
#4 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 52
Quote:
Originally Posted by
iphonig
No I didn't how do I do that?
You don't need it for something like this. Just make two comparisons.
if ([[[tableContent objectAtIndex:indexPath.row] title ] isEqual:@"Sample"] && [[[tableContent objectAtIndex:indexPath.row] summary ] isEqual:@"blah blah"])
10-14-2009, 12:35 AM
#5 (permalink )
Reena
Join Date: Apr 2009
Posts: 31
Quote:
Originally Posted by
iphonig
Hey everyone,
I'm working on an app that has a table view in it. I had no problem using it and navigation was working great but I decided that it would look more professional if I had the Name and than a mini summary of the next view when you tapped on the cell. I designed my custom cell but the problem I am having is loading up a new view when a particular cell is tapped. I used isEqual to the name of one of the arrays when I used a regular table view but now I get an error saying too many arguments to function 'isEqual'
Here is what my code looks like
Code:
NSString *customCellContent[][2] = {
{@"Sample", @"blah blah"},
{@"Sample 2", @"blah blah"},
// and it keeps going
};
@implementation Sample
@synthesize tableContent, theCustomCell;
-(void) loadTestData {
// fill moviesArray with test data
for (int i=0; i< 10; i++) {
CustomCell *theCell = [[CustomCell alloc] init];
theCell.title = customCellContent[i][0];
theCell.summary = customCellContent[i][2];
[tableContent addObject: theCell];
[theCell release];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Sample";
tableContent = [[NSMutableArray alloc] init];
[self loadTestData];
}
// 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) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self options:NULL];
cell = theCustomCell;
}
// Set up the cell...
CustomCell *aCell = [tableContent objectAtIndex:indexPath.row];
UILabel *titleLabel = (UILabel*) [cell viewWithTag:1];
titleLabel.text = aCell.title;
UILabel *summaryLabel = (UILabel*) [cell viewWithTag:3];
summaryLabel.text = aCell.summary;
return cell;
}
//here is my problem
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableContent objectAtIndex:indexPath.row] isEqual:@"Sample", @"blah blah"])
{
SampleViewController *sample = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
[sample setTitle:@"Sections"];
ApptitutorAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.sampleNavController pushViewController:sample animated:YES];
}
}
Any help would be greatly appreciated!
Thanks!
iPhonig
try this
if ([[tableContent objectAtIndex:indexPath.row] isEqual:@"Sample"] || [[tableContent objectAtIndex:indexPath.row] isEqual:@"blah blah"])
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: 242
25 members and 217 guests
ADY , AragornSG , bookesp , BrianSlick , Dani77 , Dattee , Davey555 , Dominus , dre , glenn_sayers , HemiMG , JasonR , karlam963 , M.A.S. , marshusensei , mer10 , nobre84 , Oral B , prchn4christ , Raggou , Rudy , spiderguy84 , themathminister , viniciusdamone , vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp