我对Objective C和iPhone的开发很新,并且遇到了一个完全困扰我的问题
我有一个类Sale,它有以下类方法:
+(NSMutableArray*)liveSales {
NSMutableArray *liveSales = [[NSMutableArray alloc] init];
for(int i = 0; i <= 100; i++)
{
Sale *s = [[Sale alloc] init];
//[s setTitle:[NSString stringWithFormat:@"Sale %d", i+1]];
[s setTitle:@"Title"];
//[s setDescription:[NSString stringWithFormat:@"Sale %d descriptive text", i+1]];
[s setDescription:@"Description"];
[liveSales addObject:s];
[s release];
s = nil;
}
return [liveSales autorelease];
}
然后我以下列方式使用这个类方法:
#import "RootViewController.h"
@implementation RootViewController
@synthesize liveSales = _liveSales;
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
[[self navigationItem] setTitle:@"Sales"];
if (![self liveSales])
{
[self setLiveSales:[Sale liveSales]];
}
}
然后我使用以下事件自定义表格单元格:
// 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) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
Sale *sale = [[self liveSales] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[sale title]];
[[cell detailTextLabel] setText:[sale description]];
[sale release];
sale = nil;
return cell;
}
如果我然后使用模拟器运行此代码,我可以看到每个表格单元格显示正确的信息,并且出现的所有内容正常工作,直到我滚动到列表的最底部并且应用程序将在控制台窗口中记录下列信息:
2010-02-10 20:23:50.741 AppName[1828:207] *** -[UICGColor title]: unrecognized selector sent to instance 0x3b05750
2010-02-10 20:23:50.743 AppName[1828:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UICGColor title]: unrecognized selector sent to instance 0x3b05750'
2010-02-10 20:23:50.744 AppName[1828:207] Stack: (
29291611,
2510427401,
29673531,
29242998,
29095618,
8789,
3047008,
3013271,
3089642,
3053907,
55804592,
55804015,
55802054,
55801146,
55834680,
29078098,
29075039,
29072456,
37382029,
37382226,
2764803
)
我花了几个小时试图找出这里发生的事情无济于事但我确定我要么错过了一些非常明显的东西,要么以错误的方式接近应用程序的逻辑
任何人都可以提供的帮助将不胜感激:)
由于
戴夫
答案 0 :(得分:2)
您在以下位置发布了额外的版本:
// Configure the cell.
Sale *sale = [[self liveSales] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[sale title]];
[[cell detailTextLabel] setText:[sale description]];
[sale release];
sale = nil;
sale是从数组中获取的自动释放实例,不要释放它。