Je continue à obtenir cette erreur:Pourquoi ai-je une erreur isEqualToString dans ce code Cocoa?
alt text http://img514.imageshack.us/img514/2203/help.tif
Qu'est-ce? Je n'ai même jamais appelé "isEqualToString".
Est Voici mon Joke.M
@implementation Joke
@synthesize joke;
@synthesize rating;
- (id)init {
[super init];
return self;
}
- (void)dealloc {
[joke release];
[super dealloc];
}
+ (id)jokeWithValue:(NSString *)joke {
Joke *j = [[Joke alloc] init];
j.joke = joke;
return [j autorelease];
}
@end
Et voici joke.h
@interface Joke : NSObject {
NSString *joke;
int rating;
}
+ (id)jokeWithValue:(NSString *)joke;
@property (readwrite, copy) NSString *joke;
@property (readwrite) int rating;
@end
Et voici où blague est utilisé
#import "TableViewController.h"
#import "Joke.h"
@implementation TableViewController
@synthesize jokes;
- (id)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) {
self.jokes = [NSMutableArray arrayWithObjects:
[Joke jokeWithValue:@"If you have five dollars and Chuck Norris has five dollars, Chuck Norris has more money than you"],
[Joke jokeWithValue:@"There is no 'ctrl' button on Chuck Norris's computer. Chuck Norris is always in control."],
[Joke jokeWithValue:@"Apple pays Chuck Norris 99 cents every time he listens to a song."],
[Joke jokeWithValue:@"Chuck Norris can sneeze with his eyes open."],
nil];
}
return self;
}
- (void)viewDidLoad {
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Saying how many sections wanted (Just like in address, where sorts by first name)
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [jokes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Team";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = [jokes objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[jokes release];
[super dealloc];
}
@end
Merci
Un objet est comparé comme une chaîne. Vous devez donner plus d'informations et montrer du code. Montrez le code où cela se passe. –
Kk J'ai ajouté mon code là-bas. Désolé, je n'ai pas ajouté avant –
Pourriez-vous poster le code où Joke est utilisé, et pas seulement où il est défini? – chaos