为什么我在这个Cocoa代码中得到一个isEqualToString错误? [英] Why am I getting an isEqualToString error in this Cocoa code?

查看:111
本文介绍了为什么我在这个Cocoa代码中得到一个isEqualToString错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直收到此错误:

这是什么?我从来没有调用过isEqualToString。

What is it? I never even called "isEqualToString".

这里是我的Joke.M

Here Is my 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

这里是joke.h

@interface Joke : NSObject {
NSString *joke;
int rating;
}

+ (id)jokeWithValue:(NSString *)joke;

@property (readwrite, copy) NSString *joke;
@property (readwrite) int rating;

@end

这里是使用笑话

#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

感谢

推荐答案

替换此行:

cell.text = [jokes objectAtIndex:indexPath.row];

这些行:

Joke *j = (Joke *)[jokes objectAtIndex:indexPath.row];
if( j )
  cell.text = j.joke;

这篇关于为什么我在这个Cocoa代码中得到一个isEqualToString错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆